2's complement notation


This is one of the methods of representing signed integers in the computer. In this method, the most significant digit (MSD) takes on extra meaning.

  • If the MSD is a 0, we can evaluate the number just as we would any normal unsigned integer.
  • If the MSD is a 1, this indicates that the number is negative.

The other bits indicate the magnitude (absolute value) of the number.

If the number is negative, the other bits signify the 2'scomplement of the magnitude of the number.

Thus a positive number has the same representation in SM, 1's complement, and 2's complement notations. Only negative numbers are represented differently in these notations. Somesigneddecimal numbers and their equivalent in 2's complement notation is shown below, assuming a word size of 4 bits.

Signed decimal
2’s complement
         +6
   0110
         -6
   1010
         +0
   0000
         +7
   0111
         -7
   1001

Notice that there is a single notation for 0, immaterial of whether it is +0 or –0. One may feel that 0 000 is +0 only, as the MSB, in this case, is a 0. But then, the notation for –0 should be the 2's complement of 0 000, which is1111 + 1 = 0 000 ignoring the carry.

Thus, in 2's complement, notation an extra negative number can be represented compared with SignedMagnitudeor 1's complement notation. This is because, in 2's complement notation, there is only a single notation for zero, whereas in SM and 1's complement notations there are two notations for 0.

Range

If the word size is n bits, the range of numbers that can be represented is from -(2n-1) to  +(2n-1 -1). A table of word size and the range of 2's complement numbers that can be represented is shown next.

Word size
Range for 2’s complement numbers
       4
-8 to +7
       8
-128 to +127
       16
-32768 to +32767
       32
-2147483648 to +2147483647±2 × 10+9 (approx.)

 

Example 1 − Add the numbers (+5) and (-3) using a computer. The numbers assumed to be represented using 4-bit 2's complement notation.

             1101 <- carry generated during addition

             0101 <- (+5)

           + 1101 <-(-3)

             0010 <- (+2) Sum


So in this method, that the computer straightaway gives the correct answer of +2 = 0010.

Disadvantages

  • 2's complement notation is not very simple to understand because it is very much different from the conventional way of representing signed numbers.

Advantages

  • There is a single notation for zero, which is very convenient when the computer wants to test for a 0 result.

  •  It is very convenient for the computer to perform arithmetic. The addition operation straightaway gives the correct result.

Hence, 2's complement notation is generally used to represent signed numbers inside a computer.

Updated on: 27-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements