Negative Number Representation
Negative Number Representation
E.g. 1) 12-6. This is the same as 12+ (-6). Let us represent -6 using 1s complement using 5 bits.
6=00110 -6=11001 in 1s complement. 12=01100
12-6 01100
+11001
100101
The numbers added are 5 bit number but the result is 6 bit number. This makes condition 1 to be true
above. So add the left most bit i.e. 1 in this case, to the right most side of result.
00101
+ 1
00110
2) 6-12. this is the same as 6+(-12). Let us represent -12 using 1s complement using 5 bits.
12=01100 -12=10011 6=00110
6-12 00110
+10011
11001
The result is 5 bit number and numbers added are 5 bit numbers. This makes condition 2 to be true.
So the result is in 1s complement i.e. it is negative. To get the decimal value, change the result into
1s complement. 11001 00110 when complemented. Change 00110 into decimal adds negative
sign now. (00110)2= (6)10. Add negative sign, it will be -6. That is the result.
2s complement subtraction
Algorithm for performing A - B:
A-B = A + (-B)
Take 2s complement of B by inverting all the bits and adding 1
Add the 2s complement of B to A.
Assume you are using n bits number for the operation. If the result is:
1) (n+1) bit number, discard the (n+1)th bit
2) n bit number, the result is in 2s complement. To change the result into decimal, convert the result
into 2s complement again and add negative value before the number.
E.g. 1) 12-6. This is the same as 12+ (-6). Let us represent -6 using 1s complement using 5 bits.
6=00110 -6=11010 in 2s complement. 12=01100
12-6 01100
+11010
100110
The numbers added are 5 bit number but the result is 6 bit number. This makes condition 1 to be true
above. So discard the left most bit i.e. 1 in this case. The result is 00110
2) 6-12. this is the same as 6+(-12). Let us represent -12 using 1s complement using 5 bits.
12=01100 -12=10100 6=00110
6-12 00110
+10100
11010
The result is 5 bit and the added numbers are 5 bit. This makes condition 2 to be true. This shows
that the result is in 2s complemented. To get the decimal value of the result, change it into 2s
complement again. Then add negative sign.
11010 00101
+ 1
00110
(00110)2=(6)10
The result is -6.
Exercise
a, 11111.11
b,111001.01
c,111111.01
d,111111.1
e, NA
a,101011.1101
b,110101.1101
c,101011.1011
d,110101.1011
e, NA
a. 73.0375
b. 75.375
c. 91.375
d. 75.573
e. NA
4. Write pseudo code that reads two numbers and multiplies them together and print out their
product?
5. Write pseudo code that tells a user that the number they entered is not a 5 or a 6?