# Binary subtraction with numbers in 2's complement

How can i perform binary subtraction of two numbers that are already in 2's complement? I have to subtract 01010011 from 10100110,both numbers are in 2's complement. I know that 10100110 is -90,and 01010011 is 83,so the result should be -173. So if i use 8 bits that means that there's overflow. But i don't get how can i perform the subtraction when both the numbers are in 2's complement. If i just perform the subtraction i get the same number 01010011. How do i show the result and that there's overflow?

You cannot represent –173 using 8 bits, since the range is –128 to 127.

To subtract two numbers in two's complement, you use the identity $$a - b = a + (-b)$$. In your case, $$a = 10100110$$, $$b = 01010011$$, and $$-b = 10101101$$. Adding $$a$$ and $$-b$$, there is overflow, so you know that the number is outside the range.

You need to subtract 01010011 from 10100110.

10100110 - (01010011)

So find the 2's complement of 01010011 which is 10101101 and just add it to 10100110

 01011000   <=carry bits

10100110
+10101101
----------
101010011 <= Result, but the extra 9th bit to the left of MSB is stored outside a register in a special carry out flip-flop



Now the carry-in and carry out of the MSB of the 8 bit register are different and so the result is overflow... (the carry in is 0 ,above the two 1's in the MSB and the carry out is 1 which is left to the MSB in the result)

If and only if the XOR of the carry-in and carry-out of the MSB is 1 then overflow.