[Math] Computing $ 001001_2 – 110101_2$ (base $2$), and representing the result in signed magnitude format

binary

I've been asked (for homework) to do $ 001001_2 – 110101_2$ (base 2) and to represent the answer in a signed magnitude format.

EDIT: I'm specifically asked:

Perform subtraction on the given unsigned binary numbers using the 2’s
complement of the subtrahend. Where the result should be negative,
find its 2’s complement and affix a minus sign.

What I did was I took the two's complement of the term being subtracted, so:

110101

(apply one's complement then add one to get the two's complement)

001010
+
000001
------
001011

Then I rewrote the problem as an addition:

001001
+
001011
------
010100

And checked my work using Wolfarm Alpha.

My answer is wrong, and I don't know why. This process worked for the other three problems like it. However I did notice that this should have been a negative number.

I'd like to know what I missed / what led to this process that works on other questions not working in this case.

Best Answer

When you are doing arithmetic two's complement, the leftmost bit is $0$ for positive numbers, $1$ for negative numbers. You started with $110101$ (base $2$), which is $53$ (base $10$) when treated as an unsigned number, but you proceeded to treat it as a six-bit number in a two's-complement representation. Since the leftmost bit is $1$, that makes it a negative number; its value then is $-11$ (base $10$). You then proceeded to take $9 - (-11)$, and produced the correct result for that problem, namely the value $20$ (base $10$).

The desired answer, $-44$ (base $10$), is not representable in six-bit two's-complement arithmetic. The range of numbers in that system is only $-32$ to $31$ (base $10$) inclusive.

To correctly treat $110101$ (base $2$) as a positive binary number while doing two's-complement arithmetic, you need to use more than six bits in your numbers, so that the leftmost bit is no longer $1$. Try rewriting your problem using seven-bit numbers, like this:

$$ 0001001 - 0110101 \mbox{(base $2$)}. $$