1

So to convert a positive binary number into a negative one I have to invert all of the bits of the number and ​add 1.

   `byte x = 0b0111_1111;
    System.out.println(x); // 127
    
    x = 0b1111_1111_1111_1111_1111_1111_1000_0001;
    System.out.println(x); // -127

I don't understand why I have to expand my number to 32 bit form by adding zeros on the left side before reversing the bits, why exactly to 32 bit form?

Chris
  • 26,361
  • 5
  • 21
  • 42
wydra__
  • 11
  • 1

0 Answers0