Two's Complement

Last Updated : 25 Apr, 2026

There are three common ways to represent signed integers: sign-bit representation, 1’s complement, and 2’s complement. Since data is stored in bits, we need a method to store both positive and negative values in memory. To understand this, we start with a simple approach and then gradually improve it to arrive at a more efficient and practical solution.

Signed bit

In this method, the leftmost bit is used to show the sign of the number. 0 means positive and 1 means negative. The remaining bits store the value.

For example, in a 4-bit system, 1 bit is for sign and 3 bits store the number.
In an 8-bit system, 1 bit is for sign and 7 bits store the number.

Sr. No.Binary RepresentationDecimal Value
10000+0
20001+1
30010+2
40011+3
50100+4
60101+5
70110+6
80111+7
91000-7
101001-6
111010-5
121011-4
131100-3
141101-2
151110-1
161111-0

By using this approach, we are successfully able to represent signed integer. But when we analysis it more closely, we could observe following drawbacks:

1) Two representations of zero:

In sign-bit representation, the leftmost bit shows the sign and the remaining bits store the value. Because of this, zero can be represented in two ways:

  • +0 : 0000 (sign bit = 0, value = 000)
  • -0 : 1000 (sign bit = 1, value = 000)

Both represent the same value (zero), but they have different bit patterns.

Why this is a problem:

  • It wastes one possible value, so instead of 16 unique values (in 4-bit), we get only 15.
  • The system must check for both +0 and -0, which makes operations more complex.

2) Signed extension doesn’t work for negative numbers:

As data size increases, we need to extend the number of bits (for example, from 32-bit to 64-bit). A good system should allow extension without changing the value.

  • Positive numbers extend correctly by adding zeros.
  • Negative numbers do not extend correctly in sign-bit representation.
Decimal 4-bit 5-bit 6-bit
+2 0010 00010 000010
+7 0111 00111 000111
-2 1010 10010 (! = 11010) 100010 (! = 111010)
-7 1111 10111 (! = 11111) 100111 (! = 111111)

3) Binary addition doesn’t work:

Let's try to add two binary numbers:

Binary Decimal Binary Decimal Binary Decimal
Number-1 0010 +2 0111 +7 1101 -5
Number-2 1010 -2 1010 -2 0011 +3
Binary addition1100-40001+10000+0
Decimal addition+0+5-2

Binary addition does not work correctly in this representation because the sign bit is treated separately from the value bits. When we perform normal binary addition, the result becomes incorrect since the sign bit is not handled as part of the actual number. This makes arithmetic operations complex and unreliable.

1’s Complement

In this method, negative numbers are arranged in reverse order compared to the signed-bit method. This improves how negative values are handled.

Binary1’s Complement ValueSigned Bit Value
0000+0+0
0001+1+1
0010+2+2
0011+3+3
0100+4+4
0101+5+5
0110+6+6
0111+7+7
1000-7-0
1001-6-1
1010-5-2
1011-4-3
1100-3-4
1101-2-5
1110-1-6
1111-0-7

How 1’s Complement Works

  • Positive numbers are stored as they are
  • Negative numbers are formed by changing all 0s to 1s and 1s to 0s

Example:
+2 : 0010
-2 : 1101

1) Two representations of zero:

This method still has two zeros:

+0 : 0000
-0 : 1111

This creates confusion and wastes one value.

2) Bit Extension Works Properly:

Extending bits keeps the value correct:

Decimal 4-bit 5-bit 6-bit
+2 0010 00010 000010
+7 0111 00111 000111
-2 1101 11101 111101
-7 1000 11000 111000

3) Binary addition works with modified rules:

Normal binary addition gives almost correct results, but one extra step is needed.

Binary Decimal Binary Decimal Binary Decimal
Number-1 0010 +2 0111 +7 1010 -5
Number-2 1101 -2 1101 -2 0011 +3
Binary addition1111-00100+41101-2
Decimal addition+0+5-2

If there is a carry from the leftmost bit, add it back to the rightmost bit.

Binary Decimal Binary Decimal Binary Decimal
Number-1 0111 +7 1110 -1 0111 +7
Number-2 1101 -2 1001 -6 1011 -4
Binary addition(1) 0100+4(1) 0111+7(1) 0010+2
Adding carry forward back0101+51000-70011+3

2’s Complement

2’s complement is obtained by removing -0 from the 1’s complement table and shifting negative values one step down.

Binary2’s Complement1’s ComplementSign-Magnitude
0000+0+0+0
0001+1+1+1
0010+2+2+2
0011+3+3+3
0100+4+4+4
0101+5+5+5
0110+6+6+6
0111+7+7+7
1000-8-7-0
1001-7-6-1
1010-6-5-2
1011-5-4-3
1100-4-3-4
1101-3-2-5
1110-2-1-6
1111-1-0-7

How to get binary representation of an integer in 2’s complement method?

  • Positive numbers are represented similar to signed integer method
  • Negative numbers are represented by inverting every bit of corresponding positive number then adding 1 bit to it

1) One representation of zero:

Now we have only one representation of zero and it allows us to store total 16 unique values (+0 to +7 and -1 to -8).

2) Signed extension works for negative numbers:

Signed extension works perfectly for negative numbers.

Decimal 4-bit 5-bit 6-bit
+2 0010 00010 000010
+7 0111 00111 000111
-2 1110 11110 111110
-7 1001 11001 111001

3) Binary addition:

Number-1Number-2Result
0010 (+2)1110 (-2)0000 (0)
0111 (+7)1110 (-2)0101 (+5)
1011 (-5)0011 (+3)1110 (-2)
1111 (-1)1010 (-6)1001 (-7)

4) First bit is a signed bit:

  • Numbers starting with 0 : positive
  • Numbers starting with 1 : negative

5) Memory overflow check:

Overflow occurs when:

  • Carry into sign bit ≠ Carry out of sign bit
Binary Decimal Binary Decimal Binary Decimal Binary Decimal
Number-1 1011 -5 0010 2 0111 +7 1011 -5
Number-2 1100 -4 0110 6 1110 -2 0011 3
Addition (1) 0111 (0)1000 (1)0101 (0)1110
carry in to sign bit 0 overflow 1 overflow 1 no 0 no
carry out to sign bit 1 0 1 0
Comment
Article Tags:

Explore