0

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?

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
user3081703
  • 63
  • 1
  • 8

1 Answers1

0

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

A M
  • 448
  • 5
  • 11