I am reading the book Art of Assembly Language. There I came across this paragraph.
If the H.O. bit is zero, then the number is positive and is stored as a standard binary value. If the H.O. bit is one, then the number is negative and is stored in the two’s comple-ment form. To convert a positive number to its negative, two’s complement form, you use the following algorithm:
Invert all the bits in the number, i.e., apply the logical
NOT
function.Add one to the inverted result.
For example, to compute the eight bit equivalent of
-5
:0000 0101 Five (in binary) 1111 1010 Invert all the bits. 1111 1011 Add one to obtain result.
Here I want to know if 0000 0101
is 5 in decimals and 1111 1011 is -5 then how we represent 251
? Is not the same 1111 1011
? How the computer distinguishes between -5 and 251
?
When you are representing signed numbers in 8 bits, the 8th bit (the HO bit) is the sign bit. Therefore you can only use 7 bits to store the value of the number. The range for a signed number in 8 bits is -128..127. 251 can't be represented, unless you use more than 8 bits.