11
$\begingroup$

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?

$\endgroup$
  • 7
    $\begingroup$ 0 doesn't have two values. It has the value 0. Period. What it does have in 1's complement is two representations. But that's not really something unique. For example, the number 10 has infinitely many representations in decimal: 10, +10, 010, +010, 0010, +0010, … and so on. $\endgroup$ – Jörg W Mittag Apr 4 '17 at 10:36
  • $\begingroup$ Exactly. The values are only equivalence classes of the representations, and what's called “the value 0” happens to be an equivalence class containing both 000...0 and 111...1. But these two representations still make up only a single value. $\endgroup$ – leftaroundabout Apr 4 '17 at 14:26
19
$\begingroup$

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
$\endgroup$
  • 7
    $\begingroup$ It might be worth mentioning that 2's complement has more advantages to it beside just one more number in the range, even if you don't go into details what they are. $\endgroup$ – KRyan Apr 4 '17 at 0:11
  • 7
    $\begingroup$ Might as well mention one of said advantages in this here comment section: One of the major advantages is subtraction (/ addition of negative numbers) can be implemented just by pretending the numbers are unsigned and adding them. No special cases needed for subtraction = much simpler circuitry and logic. This page has a nice write-up on that topic. $\endgroup$ – Jason C Apr 4 '17 at 3:37
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Ones complement addition or subtraction works with end-around carry. Of course, what's displayed to the programmer need not be the underlying representation. $\endgroup$ – ttw Apr 4 '17 at 4:15
  • 1
    $\begingroup$ @ttw The question asks what the two representations of zero are, so I'm not sure where addition, subtraction and programmers come into it. $\endgroup$ – David Richerby Apr 4 '17 at 8:28
3
$\begingroup$

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$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.