Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Subtraction of signed binary numbers using 2’s Complement

In this article, we will perform a subtraction using 2’s Complement. An unsigned binary number does not have a sign bit in the most significant bit (MSB) position. For example, consider 8-bit representation of 3810

3810 = 01001002

= 0. 27 + 0. 26 + 1. 25 + 0. 24 + 0. 23 + 1. 22 + 0. 21 + 0. 20

= 0 + 0 + 32 + 0 + 0 + 4 + 0 + 0

= 34 + 4

= 3810

Now, if we take two’s complement of unsigned binary number then we get signed binary representation of a number which is nothing but negative equivalent the unsigned binary number.

To understand this in an easy way, consider previous example of 3810. Let us convert the number 3810 into binary.

3810 = 0 0 1 0 0 1 0 0

Take 1’s complement of each binary digit in above number. That is, 0 becomes 1 and 1 becomes 0.

= 1 1 0 1 1 0 1 1

Adding 1 to the 1’s complement of 3810 we get two’s complement of the binary number.


                          1 1
                1 1 0 1 1 0 1 1
                +             1
               __________________
                1 1 0 1 1 1 0 0

The Most Significant Bit (MSB) has 1 which shows that it is a negative number. The resultant number is -3810

Subtraction using 2’s Complement of unsigned binary number

Two’s complement of binary number is used for subtraction between unsigned and signed binary numbers.

For example,

How do we subtract?  -34 – (-45) = -34 + 45 = 11

Step 1:  Convert +34 in 2’s Complement form.

34 = 0 0 1 0 0 0 1 0

Obtain 1’s complement of 0 0 1 0 0 0 1 0


                    
                0 0 1 0 0 0 1 0
                +             1
               __________________
                0 0 1 0 0 0 1 1

= -3410

Note:  The above step is only performed to obtain the -34 values. There are other methods to obtain negative signed values

Step 2:  Convert -45 into 2’s complement to find +45.

But we can also do it directly.

450 = 0 0 1 0 1 1 0 1 = 0. 27 + 0. 26 + 1. 25 + 0. 24 + 1. 23+ 1. 22 + 0. 21 + 1. 20

= 0 + 0 + 32 + 0 + 8 + 4 + 0 + 1

= 32 + 8 + 4 + 1

= 45

Step 3:  Add binary value of -34 and 45


                1 1 0 1 1 1 1 0   = -34
                0 0 1 0 1 1 0 1   = +45
                ____________________
                0 0 0 0 1 0 1 1 = 1 1 1 0

Example Problems

Q 1: Perform the subtraction with the unsigned binary numbers by taking the 2’s complement of the subtrahend.

Source: Computer System Architecture by Morris Mano

a) 1 1 0 1 0 – 1 0 0 0 0

Solution:

Given


                1 1 0 1 0 = + 26

                1 0 0 0 0 = + 16

                Take 1's complement of 1 0 0 0 0

              = 0 1 1 1 1

                Add +1 to get 2's complement of + 16

                Add the binary value of +26 and -16

               1
               0 1 1 0 1 0 = +26
               0 1 0 0 0 0 = -16
               _________________
               1 0 1 0 1 0 = +10

= 10 is the answer.

b) 1 1 0 1 0 – 1 1 0 1

Solution:

Given



                1 1 0 1 0 = +26

                0 1 1 0 1 = +13

                Take 1's complement of +13 = 0 1 1 0 1

                = 1 0 0 1 0

                Add 1 to get 2's complement of +13

                1 0 0 1 0 
                +       1
                _____________
                1 0 0 1 1

                Add binary values of +26 and -13
                to get the result.

                      1  
                0 1 1 0 1 0 = +26
                0 1 0 0 1 1 = -13
                _____________
                1 0 1 1 0 1 = -13

The answer is +13.

c) 100 – 110000

Solution:



                0 0 0 0 0 1 0 0 = +4

                0 0 1 1 0 0 0 0 = +48

                Take 1's complement of 48

                = 1 1 0 0 1 1 1 1

                Add 1 to get the 2's complement of + 48

                      1 1 1 1 
                0 1 1 0 1 1 1 1 = +48
                +             1 
                _________________
                0 1 1 1 0 0 0 0

                Add the binary values of +4 and -48 
                to get the correct answer.

                0 0 0 0 0 1 0 0 = +04
                1 1 0 1 0 0 0 0 = -48
                _____________________
                1 1 0 1 0 1 0 0 = -44

-44 is the answer.

d) 1010100 – 1010100

Solution:



                0 1 0 1 0 1 0 0 = 64 + 16 + 4 = +84
                0 1 0 1 0 1 0 0 = 64 + 16 + 4 = +84

                Take 1's complement of +84 subtrahend

                = 1 0 1 0 1 0 1 1

                Add 1 to get the 2's complement 
                of +84 subtrahend

                            1
                1 0 1 0 1 0 1 1
                +             1
                _______________

                Add the binary values of +84 and -84 
                to get the result.

                1 1 1 1 1
                0 1 0 1 0 1 0 0
                1 0 1 0 1 1 0 0
                _______________
                0 0 0 0 0 0 0 0

The answer is zero.

References

  • Mano, M. Morris. 1984. Digital Design. Pearson.
  • Shjiva, Sajjan G. 1998. Introduction to Logic Design. New York: Marcel Dekker, Inc .
Previous
Next

The post Subtraction of signed binary numbers using 2’s Complement appeared first on Notesformsc.



This post first appeared on Notesformsc, please read the originial post: here

Share the post

Subtraction of signed binary numbers using 2’s Complement

×

Subscribe to Notesformsc

Get updates delivered right to your inbox!

Thank you for your subscription

×