Advantage of 2's complement over 1's complement?

BinaryNegative Number

Binary Problem Overview


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?

Binary Solutions


Solution 1 - Binary

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:

Solution 2 - Binary

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
            

Solution 3 - Binary

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.

Solution 4 - Binary

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.

Solution 5 - Binary

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

Solution 6 - Binary

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpranphyView Question on Stackoverflow
Solution 1 - BinaryJYeltonView Answer on Stackoverflow
Solution 2 - BinaryGAURAV SINGHView Answer on Stackoverflow
Solution 3 - BinaryCoding activeView Answer on Stackoverflow
Solution 4 - BinaryMuhammad Shaheer RiazView Answer on Stackoverflow
Solution 5 - BinaryTechunoView Answer on Stackoverflow
Solution 6 - BinaryTony HopkinsonView Answer on Stackoverflow