The numbers work as follows.
The leftmost bit in an eight bit byte is the sign bit.
1 0 1 0 1 0 1 0
^
^ The sign bit has a value of -128 decimal or -80 hexadecimal.
The other seven bits are treated as a normal positive number between 0 and 127. This is true whether the overall number is positive or negative. For example to store -1 the binary is
1 1 1 1 1 1 1 1 - 128d + 127d = -1d
^
^ -128d
To store 127 decimal, the binary is
0 1 1 1 1 1 1 1 0 + 127d = 127d
^
^ The sign bit is zero.
16 and 32 bit machines also use the leftmost bit as the sign bit. The negative numbers work in exactly the same way but much bigger niumbers can be stored. In a 16 bit machine, the sign bit is worth -32768. In a 32 bit machine, the sign bit is worth -2147483648 (2000 million approximately).
Share with your friends: |