a) Signed bit

When trying to store a signed integer, it seems obvious to reserve the left most bit for sign and use remaining bits to actually store the values. For example: in 4-bit system, first bit from left will be reserved for sign (0 represent positive whereas 1 represent negative) and other 3 bits will be used to store the values. Similarly in 8-bit system, first bit from left will be used for sign and remaining 7 will be used for values.

Sr. No.

Binary Representation

Decimal Value

A

0000

+0

B

0001

+1

C

0010

+2

D

0011

+3

E

0100

+4

F

0101

+5

G

0110

+6

H

0111

+7

I

1000

-0

J

1001

-1

K

1010

-2

L

1011

-3

M

1100

-4

N

1101

-5

O

1110

-6

P

1111

-7

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 4-bit system, we should be able to store 16 (24) values, but +1 to +7 and -1 to -7 are only 14 values. Where are remaining two values? When we observe the table carefully, we will find out that those two values converge to 0. Thus, we have two representations of zero, that means, one representation for +0 and another for -0.
 

But are two representations of 0 a big concern? So what? Instead of 16 unique values, we are only able to store 15 values. We can afford to reduce the range by 1, isn’t it? To the software developer, it might not concern but for a circuit designer it might be very frustrating to first check if value is +0 and then to check if it -0.
 

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

Size of the data is increasing rapidly. Some time we need to extend the bit system so that we can increase the range of data that can be stored. In 2014, Gangnam Style video overflowed YouTube view limit and it forced YouTube to upgrade view count from 32-bits to 64-bits signed integer. Similarly, 32-bit Unix clock will overflow on 19 Jan 2038 because it records time in seconds in a 32-bit signed integer.

So, it is equally important that our representation system should be extendable easily which is not possible with this representation system. 

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 addition

1100

-4

 

0001

+1

 

0000

+0

Decimal addition

 

+0

 

 

+5

 

 

-2

Why is a simple binary addition not working here? The reason is that the sign bit (left most) is not an ordinary bit and not part of actual number. Imagine the situation where one has to design the hardware circuitry to ignore the sign bit to perform addition and then append the sign bit.

So, this was a naïve way to represent signed integer. The main problem with this approach is that we have mapped negative numbers down up. If we change our mapping system to top down them some of above issue will be resolved.

Two’s Complement

There are three different ways to represent signed integer (article). a: Signed bit, b: 1’s Complement, and c: 2’s Complement. Let’s try to understand how these methods have derived and why 2’s complement is preferred over others.

As we know that data are stored in bits. How can we store signed integer in the memory? To solve this problem, first we will develop a naïve solution and then will iterate it till we have the best solution for our problem.

Similar Reads

a) Signed bit

When trying to store a signed integer, it seems obvious to reserve the left most bit for sign and use remaining bits to actually store the values. For example: in 4-bit system, first bit from left will be reserved for sign (0 represent positive whereas 1 represent negative) and other 3 bits will be used to store the values. Similarly in 8-bit system, first bit from left will be used for sign and remaining 7 will be used for values....

b) 1’s Complement

If we remap our negative numbers from top-down, then we will be getting following binary table:...

c) 2’s Complement

When we remove -0 from the 1’s complement table and shift all negative values one row below, then we will get following table which is called 2’s complement:...