To perform a binary subtraction you first have to
represent the number to be subtracted in its negative
form. This is known as its two's complement.
The two's complement of a binary number is obtained by:
- Replacing all the 1's with 0's and the 0's with 1's.
This is known as its one's complement.
- Adding 1 to this number by the rules of binary
addition.
Now you have the two's complement. Example:
The decimal subtraction 29 - 7 = 22 is the same as adding
(29) + (-7) = 22
-
Convert the number to be subtracted to its two's
complement:
| 00000111 |
(decimal 7) |
| 11111000 |
(one's complement) |
| + 00000001 |
(add 1) |
| 11111001 |
(two's complement) |
11111001 now represents -7.
Add
| 29 |
00011101 |
| +- 7 |
11111001 |
| 22 |
(1)00010110 |
Note that the final carry 1 is
ignored.
|