how to calculate the one's complement for positive and negative number?

Dean Chen picture Dean Chen · Jun 2, 2012 · Viewed 44.9k times · Source

If I use one's complement to represent number, what result should I get?
For example, number 01110 ( a positive number),its one's complement should be 01110 or 10001?
if the number is 10001 ( a negative number), the one's complement value is 01110?

Answer

Eran Zimmerman Gonen picture Eran Zimmerman Gonen · Aug 14, 2012

In your case, it would be 10001. Ones' complement means reversing all the bits in the number.

This also implies that it turns a positive number to a negative one, and vice versa. Also note that this gives some strange behavior, for example zero's complement isn't zero, but negative zero: 00000 becomes 11111. This makes arithmetic with 1's complement a bit tricky, and it is one of the reasons that computers today use 2's complement for negation.