73

What is the advantage of 2's complement over 1's complement in negative number representation in binary number system? How does it affect the range of values stored in a certain bit representation of number in binary system?

JYelton
  • 35,664
  • 27
  • 132
  • 191
pranphy
  • 1,787
  • 4
  • 16
  • 22
  • 4
    I think this Wikipedia article should answer this question sufficiently: http://en.wikipedia.org/wiki/Signed_number_representations – JYelton Jun 15 '12 at 15:57
  • 2
    It is not a question of advantage. The first step in two's complement IS one's complement. After that one is added to eliminate the presence of a positive zero and a negative zero. (You must eliminate a bit because you "bought" a bit to carry the sign -- and that eliminates TWO values from use in the bit width you are using.) – jinzai Jan 17 '18 at 21:34

6 Answers6

78

The primary advantage of two's complement over one's complement is that two's complement only has one value for zero. One's complement has a "positive" zero and a "negative" zero.

Next, to add numbers using one's complement you have to first do binary addition, then add in an end-around carry value.

Two's complement has only one value for zero, and doesn't require carry values.

You also asked how the range of values stored are affected. Consider an eight-bit integer value, the following are your minimum and maximum values:

Notation     Min   Max
==========  ====  ====
Unsigned:      0   255
One's Comp: -127  +127
Two's Comp: -128  +127

References:

JYelton
  • 35,664
  • 27
  • 132
  • 191
  • 4
    To generalize it: For N-bit, One's compliment can represent integers in range `−(2^(N−1)−1) to 2^(N−1)−1` and Two's compliment can represent integers in range `−2^(N−1) to 2^(N−1)−1`. – Prince Dec 29 '13 at 17:35
25

The major advantages are:

  1. In 1's there is a -0 (11111111) and a +0 (00000000), i.e two value for the same 0. On the other hand, in 2's complement, there is only one value for 0 (00000000). This is because

    +0 --> 00000000
    

    and

     -0 --> 00000000 --> 11111111 + 1 --> 00000000
    
  2. While doing arithmetic operations like addition or subtraction using 1's, we have to add an extra carry bit, i.e 1 to the result to get the correct answer, e.g.:

           +1(00000001)
         +
           -1(11111110)
         -----------------
         = (11111111)
    

but the correct answer is 0. In order to get 0 we have to add a carry bit 1 to the result (11111111 + 1 = 00000000).

In 2's complement, the result doesn't have to be modified:

               +1(00000001)
              +
               -1(11111111)
         -----------------
              = 1 00000000
Kindred
  • 1,229
  • 14
  • 41
GAURAV SINGH
  • 251
  • 3
  • 3
7

Negative integers : 2's complement makes sense to be used for negative integers. 1's complement is just a computation technique which might be helpful to evaluate 2's complement. The real (defeated) rival of 2's complement was the sign-magnitude representation for negative integers.

No overflow : 1's complement has no special usage for negative integers. 2's complement makes sense because it can be used in natural addition and subtraction arithmetic without any need to change the bits. Providing that no overflow occurs, the sign bit of the result is just the right value. The bit number promotion in this notation is straight forward, for example, to promote an 8-bit signed integer to 16, we could simply repeat the sign bit of integer value in the high byte of it.

Sign magnitude : On the contrary, the sign-magnitude notation is just the way that human uses to represent negative integers. The bit number promotion and addition subtraction arithmetic is a bit mess with this notation.

Coding active
  • 1,620
  • 3
  • 23
  • 40
3

Advantages of Two’s Complement #1

In Two’s Complement representation, the value zero is uniquely represented by having all bits set to zero:

**

Advantages of Two’s Complement #2

** When you perform an arithmetic operation (for example, addition, subtraction, multiplication, division) on two signed integers in Two’s Complement representation, you can use exactly the same method as if you had two unsigned integers (that is, nonnegative integers with no sign bit) ... EXCEPT , you throw away the high carry (or the high borrow for subtraction)

Advantages of Two’s Complement #3

This property of Two’s Complement representation is so

incredibly handy that virtually every general

purpose computer available today uses Two’s Complement. Why? Because, with Two’s Complement, we don’t need special algorithms (and therefore extra circuitry) for arithmetic operations that involve negative values.

2

Another major advantage of Two's complement over signed bit representation is 2's complement representation is easy to manipulate in hardware

Techuno
  • 21
  • 1
  • Isn't this hen-egg problem though? since the hardware would optimize whichever one was chosen... – Pacerier Apr 04 '17 at 07:30
  • 1
    @Pacerier, no it's not. It doesn't matter whether the hardware would optimize whichever one is chosen. It's the fact that the circuitry (system of logic gates connected together) required to build the hardware needed to optimize addition & subtraction on 1's complement numbers would be more complicated then the circuitry of the hardware needed to optimize addition & subtraction on 2's complement. – user904542 May 13 '17 at 00:41
  • 1
    @user904542, Do you mean **all** electronic hardware? Hmm, what about new biocomputers? – Pacerier Aug 07 '17 at 01:17
1

2s complement isn't for representing a negative number it's an inverse.

Means you can do A + B' (where B' is the 2s complement of B) to give A - B, means you can do everything with an adder and not need a substracter

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39
  • Did you mean that its not two's compliment that represent negative number but 2's compliment are represented by negative number? – pranphy Jun 15 '12 at 16:11
  • Nope 2s complement is the decimal equivalent of * -1. 2s complement of a negative number is positive as in the most significant bit is zero – Tony Hopkinson Jun 15 '12 at 22:10