The general problem is in the process of (decimal) subtraction:
Let us start with considering one digit numbers:
Assume that A and Bare positive (decimal) digits. THEN:
(9 - B) is the "9's complement" of B that can be easily computed from the following table:
For any decimal value of X and Y not greater than 99999 we can show that:
Where 99999 - abs(Y) = 9's complement of Y
(99999 - abs(Y) + 1) is the 10's complement of Y
(Note that the additive factor is of magnitude 10 times the largest of X or Y)
For binary representation in the computer the problem is easier since (a) the number of digits is only 2, and (b) and we always know how many digits are in each representation. The two complementary representations are called "2's complement" and "1's complement".
and the 2's complement is simply the 1's complement plus 1!
2710 = 00110112
- 2710 = 11001002 + 1 = 11001012
3610 = 01001002
- 3610 = 10110112 + 1 = 10111002
Last updated 2001/10/18
© J.A.N. Lee, 2000.