Binary subtraction A0 - E4

106 Views Asked by At

I have two numbers. The negative one is translated using 2's complement.

$$ a = 160_{10} = A0_{16} = 1010 0000_{2} \\ b = -28_{10} = E4_{16} = 1110 0100_{2} $$

And I have to perform the following operation $a - b$. I use borrowing up to the very last bit, but then I have a situation like.

$$ \begin{matrix} & 0 & 1 \\ - & 1 & 1 \\ & ? & 0 \\ \end{matrix} $$

Should I borrow from something imaginary? In decimal $1 - 3 = -2$, so the answer is $BC$, but how do you reason about the negative $2$ here?

3

There are 3 best solutions below

0
On BEST ANSWER

Here's one way to do it. Sign-extend your operands one bit to the left, i.e. duplicate the most significant bit. Your operands are both negative, so they will become $1A0_{16}$ and $1E4_{16}$. Now perform $9$-bit subtraction, and simply throw away the final borrow. You get $1BC_{16}$.

Here the two top bits are the same, so you can just discard the top bit to get $BC_{16}=-68_{10}$ as your 2's complement answer.

If the two top bits are different, then overflow or underflow has occurred, and the 8-bit result is out by $\pm256$.

3
On

Subtraction is always done with the smaller number being subtracted from the bigger number.

So if $b>a$, $$a-b=-|b-a|$$

Perform $b-a$ and add the minus symbol.

3
On

So we have the following subtract problem:

$$a-b = 10100000_2 - 11100100_2$$

Whenever we arrive a point where we need to "borrow" like we do in normal subtraction, we simply change the top number to a $2$, as we do in normal subtraction where we borrow from the previous number and add $10$ to it.

Then, we must subtract $1$ from the number we "borrowed" from.

If you are still unclear, this link might be able to help you.