Binary subtraction with 2's complement

I need help for subtraction with binary using 2 representation and using 5 bits for each number:

1) -9 -7 =? Is there an overflow?

-9 = 01001 (2 complements = 10111) and -7 = 00111 (2 complements = 11001)

Now we need to add because we are using 2 addons

10111 +11001 = 100000 But this answer doesn't make sense. Also, I assume there is an overflow because there are more than 5 bits in the response.

2) 6-10, as before. Negative binary numbers don't make sense to me

+3


source to share


4 answers


1) -9 - 7

-9 - 7 = -9 + -7

9 (binary) = 01001
-9 (2 complements) = 10111
7 (binary) = 00111
-7 (2's complements) = 11001

 10111 +
 11001 =
110000

      

This does not correspond to 5 bits. Removing the overflow gets 10000, which is -16 (binary).



2) 6 - 10

6 - 10 = 6 + -10

6 (binary) = 00110
10 (binary) = 01010
-10 (2 complements) = 10110

 00110 +
 10110 =
 11100

      

This is inserted into 5 bits and is -4 (binary).

+7


source


10111 + 11001 is not 100000, but 110000.



   1111
   10111
 + 11001
   -----
  110000

      

0


source


The answer to the first question is incorrect. To find -9-7 using two's complement, we have to follow these steps:

STEP: 1 Convertion of first number

1st the binary conversion of 9: 01001

2nd find the complement of binary: 10110

Add 1 to the binary complement: 10110  
                                       +1
                                    -----
                                    10111  
STEP 2: Convertion of second number

1st the binary conversion of 7:00111

2nd find the complement of binary: 11000

Add 1 to the binary complement: 11000 
                                       +1
                                   -------
                                    11001
STEP 3: Adding

Now add the two outputs -9 + (-7): 10111
                                   +11001
                                  --------
                                   110,000
The most important thing is checking the answer whether it is correct or not.
you may use index for the binary digits: 7 6 5 4 3 2 1 0
                                                   1 1 0 0 0 0

find the 2 raised to the power of each index having 1 digit.
                                                (-) 2 ^ 5 + 2 ^ 4

* Note (-) is used because in two's complement, the most significant bit (the bit with the highest index) is the sign bit -2 ^ 5 + 2 ^ 4 = -32 + 16 = -16 is the correct answer for -9 -7 = - sixteen. For this reason, 2's complement is becoming a popular way to represent negative numbers. For sign magnitude, we need to accept the sign bit, which is difficult to implement on a computer, and for 1's complement, we need to add 1 to find the correct answer.

0


source


Convert binary using 2 compliments

0


source







All Articles