In: Computer Science
Problem 5: Perform the subtraction on the following pairs of signed numbers using the 2’s complement system. Express the results as signed binary numbers and as decimal values. Please show all work to fully understand.
A. 01001 - 11010 B. 10010 - 10011
A. Given pair of signed numbers are : 01001,11010
Binary | Decimal value |
01001 | 9 |
11010 | 26 |
01001 - 11010 = 9 - 26 = 9+(-26)
Using the 2’s complement : -26 = 2's complement of 26
2's complement of a number is nothing but 1's complement of number + 1.
26 = 11010, 1's complement of 26 is 00101.
Note : 1's complement is just inversion of all bits in the given number.
2's complement of 26 : 00101 + 1= 00110.
-26 = 00110
Decimal | Binary | |
9 | 0 1 0 0 1 | |
+ | -26 | 0 0 1 1 0 |
Result | -17 | 0 1 1 1 1 |
0 1 1 1 1, there is no carry in the result. It is clear that the result is negative.
Inversion of all bits : 10000 [Inversion of 01111]
Adding 1 : 10000+1 = 10001
Binary representation of 17 is (10001)2.
Conclusion : The result is -17. [which is equivalent to decimal result]
B. 10010 - 10011
(10010)2 = (18)10 , (10011)2 = (19)10
18-19 = 18+(-19)
-19 = 2's complement of 19
2's complement of 19 = 01100 + 1 = 01101 [ 1's complement of 19 + 1]
Decimal | Binary | |
18 | 1 0 0 1 0 | |
+ | -19 | 0 1 1 0 1 |
Result | -1 | 1 1 1 1 1 |
Here also there is no carry in the result. It is clear that the result is negative.
Note : We know that -1 is represented as all 1's in 2's complement form.
Inversion of all bits : 00000 [Inversion of 11111]
Adding 1 : 00000+1 = 00001
Conclusion : The result is -1. [which is equivalent to decimal result]