Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two's complement, why the name "two"

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

  1. why it's called two's(or ones') complement, so is there a more generalize N's complement?
  2. in which way did these genius deduce such a natural way to represent negative numbers?
like image 713
mochidino Avatar asked Apr 09 '10 00:04

mochidino


People also ask

What is signed 2 complement?

Signed 2's complement (or sign 2's complement) (s2c) is a modification of the sign-magnitude form in which addition and subtraction work the way that you expect them to. The price we pay is that we can't read a negative number directly.


1 Answers

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 "one's complement" is named for the "diminished radix complement", which is the radix minus one. If you look at this for decimal, the meanings behind the names makes more sense.

Method of Complements (Wikipedia)

like image 54
staticsan Avatar answered Sep 20 '22 12:09

staticsan