binarycomputer-science

Two's complement: why the name "two"?


I know unsigned, two's complement, ones' complement, sign magnitude, and the difference between these. But what I'm curious about is:

  1. Why is it called two's (or ones') complement? Is there a more general N's complement?
  2. In which way did these geniuses deduce such a natural way to represent negative numbers?

Solution

  • Two's complement came about when someone realized that 'going negative' by subtracting 1 from 0 and letting the bits rollunder actually made signed arithmetic simpler because no special checks have to be done to check if the number is negative or not. Other solutions give you a discontinuity between -1 and 0. The only oddity with two's complement is that you get one more negative number in your range than you have positive numbers. But, then, other solutions give you strange things like +0 and -0.

    According to Wikipedia, the name itself comes from mathematics and is based on ways of making subtraction simpler when you have limited number places. The system is actually a "radix complement" and since binary is base two, this becomes "two's complement". And it turns out that "ones' complement" is named for the "diminished radix complement", which is the radix minus one (in binary, that's a number consisting entirely of ones). If you look at this for decimal, the meanings behind the names make more sense.

    Method of Complements (Wikipedia)