Two’s Complement Representation



Two’s Complement Representation 

Let A be an n-bit signed binary number in two’s complement form.  

The most significant bit represents the sign.  If it is a “0”, the number is positive, and if it is “1” the number is negative.  

The remaining (n-1) bits represent the magnitude, but not as a simple weighted number.  

Consider the following two’s complement numbers and their decimal equivalents:


There is only one representation of “0”, namely 000....0.  

From these illustrations we observe 

If most significant bit (MSD) is zero the remaining (n-1) bits directly indicate the magnitude.  

If the MSD is 1, the magnitude of the number is obtained by taking the complement of all the remaining (n-1) bits and adding a 1. 

Consider the two’s complement representation of -6.  

We assume we are representing it as a 7-bit number.

Leave the sign bit. 

The remaining bits are 111010.  These have to be complemented (that is 000101) and a 1 has to be added (that is 000101 + 1 = 000110 = 6).  

 

In the example shown above a 7-bit number can cover the range from +63 to -64.  In general an n-bit number has a range from + (2n-1 - 1) to - (2n-1) with one representation for zero.

The representation also suggests that if A is an integer in two’s complement form, then

         Two’s complement of A = -A

Two’s complement of a number is obtained by complementing all the digits and adding ‘1’ to the LSB.  

This relationship can be extended to fractions as well.  

If A = 0.101 (+0.625)10, then the two’s complement of A is 1.011, which is two’s complement representation of (-0.625)10.  

Similarly consider the case of a mixed number.

                                      A = 010011.0101   (+19.3125)10

         Two’s complement of A = 101100.1011   (- 19.3125)10

This relationship can be used to determine two’s complement representation of negative decimal numbers.

Example 2: What is two’s complement binary representation of decimal number -75?

Decimal number 75 requires 7 bits to represent its magnitude in the binary form.  One additional bit is needed to represent the sign.  Therefore,

 Two’s complement representation of 75  = 01001011

 Two’s complement representation of -75 = 10110101 

Uploaded Thu, 21-Jan-2021
Related Articles

Lesson meta keywords and meta description:



Bootstrap Example