# Computing $001001_2 - 110101_2$ (base $2$), and representing the result in signed magnitude format

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

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.

• For the second number $110101$, is this a signed or unsigned number? – Adriano Aug 22 '14 at 18:22
• Your answer is right if computations are done in 2-complement on 6 bits. @Adriano notice that in 2-complement arithmetic, this is completely irrelevant: you use the same subtraction for signed or unsigned numbers. – Jean-Claude Arbaut Aug 22 '14 at 18:24
• The question states: "Perform subtraction on the given unsigned binary numbers using the 2’s complement of the subtrahend." – Cody Smith Aug 22 '14 at 18:25
• @CodySmith With your question restated, your result is actually wrong: you are asked to use a sign if the signed result is negative. Si the correct answer is -101100. – Jean-Claude Arbaut Aug 22 '14 at 18:29
• If you use Windows, you can open Calculator and go to View, then "Programmer". It allows you to do base conversions between common bases by typing in your value and switching from one base to the next; it just changes how the value is represented. – person27 Aug 22 '14 at 18:34

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)}.$$