The general problem is in the process of (decimal) subtraction:

Let us start with considering one digit numbers:

Assume that *A* and *B*are positive (decimal) digits. THEN:

where (10 -

THEN:

(9 - *B*) is the "9's complement" of *B* that can be easily computed from the following table:

0 | 9 |

1 | 8 |

2 | 7 |

3 | 6 |

4 | 5 |

5 | 4 |

6 | 3 |

7 | 2 |

8 | 1 |

9 | 0 |

For any decimal value of *X* and *Y* not greater than 99999 we can show that:

That is,

Where 99999 - abs(*Y*) = 9's complement of *Y*

and

(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".

0 | 1 |

1 | 0 |

and the 2's complement is simply the 1's complement plus 1!

27_{10} = 0011011_{2}

- 27_{10} = 1100100_{2} + 1 = 1100101_{2}

36_{10} = 0100100_{2}

- 36_{10} = 1011011_{2} + 1 = 1011100_{2}

Last updated 2001/10/18

© J.A.N. Lee, 2000.