Every number primitive in
java is use the MOST LEFT BIT to represent for sign symbol. This mean the maximum value of each primitive is 2
power (bit number - 1).
Example for byte:
This primitive has totally 8 bits that mean it use 1 bit for represents sign(-/+) and 7 bit for its value.
1 is - and 0 is + for sign bit.
But This is not the whole story. In java language, it use two complement method for convert from positive value to negative.
The method is:
Example
byte x = 13; ---> 0000 1101
byte y = -13; ---> 1000 1101 (Does it correct? NOOO)
-13 is can't be simply convert from 0000 1101 to 1000 1101 but it use two complement method by following.
0000 1101 ---> 13
~
1111 0010 ---> one complement value
+
1
---------
1111 0011 ---> -13
So we return to our problem byte -16
0001 0000 ---> 16
~
1110 1111 ---> one complement value
+
1
---------
1111 0000 ---> -16
So that it. If you don't clear feel free to told me.
Tanakorn