13

It is said that in 2's complement 0 has only one value, while in 1's complement both +0 and -0 have separate values. What are they?

wizzwizz4
  • 125
  • 7
user136782
  • 233
  • 1
  • 2
  • 5

3 Answers3

20

In 1's complement you just invert all the bits.

Consider these 2 examples (assuming 8 bits):

  • $4 = 00000100$, so $-4= 11111011$

  • $0 = 00000000$, so $-0=11111111$.

So you have 2 ways to represent the number 0

In 2's complement you add 1 to the 1's complement representation of the negative number

  • $-4$ that in 1's complement was $11111011$ becomes $11111100$
  • $-0$ that in 1's complement was $11111111$ becomes $00000000$ same as 0

So you have just one way to represent the 0 in this case

As you can see from the examples the difference is that:

  • in 1's complement, with 8 bits you can just express numbers from $-2^{7}+1$ to $2^7-1$ (from -127 to 127)
  • in 2's complement with 8 bits you can express numbers from $-2^{7}$ to $2^{7}-1$ (from -128 to 127), so one more number
Jason C
  • 402
  • 1
  • 3
  • 11
abc
  • 1,675
  • 2
  • 12
  • 22
3

In ones' complement, you negate a number by flipping all the bits. Therefore, negating zero, $0\dots 0$ yields $1\dots 1$, which represents $-0$, which is the same thing as zero.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
3

Speaking of two different values of 0 in one's complement is misleading. One's complement (and two's complement) are binary representations of numbers. They describe a way to represent numbers in binary, and how to do arithmetic operations on them. The number that is represented by the sequence of bits is the value.

When you have some value in one's complement, and want to find the representation of the value with the sign flipped - the additive inverse - you invert every bit. This includes zero, so there is a representation for $0$ and a representation for $-0$. But $0 = -0$: inverting the sign on $0$ doesn't give you a different value, it gives you the same value.

That gives you two representations for $0$ in one's complement: the bit sequence $0\dots 0$ and the bit sequence $1\dots 1$.

Martijn
  • 151
  • 4