I have a byte 11001000, when I cast it to char type, it automatically adds 1s to its left so it now becomes 1111111111001000.
Why is that?
And how to avoid it so I can get a 0000000011001000?
I have a byte 11001000, when I cast it to char type, it automatically adds 1s to its left so it now becomes 1111111111001000.
Why is that?
And how to avoid it so I can get a 0000000011001000?
I am not sure why there are 1s instead of zeros but a character in Java is 16 bits and thats why there are 16 digits. Maybe you can use the & operator to get rid of those 1s.
11111111111111 & 0000000011001000