2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ For the second number $110101$, is this a signed or unsigned number? $\endgroup$ – Adriano Aug 22 '14 at 18:22
  • $\begingroup$ 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. $\endgroup$ – Jean-Claude Arbaut Aug 22 '14 at 18:24
  • $\begingroup$ The question states: "Perform subtraction on the given unsigned binary numbers using the 2’s complement of the subtrahend." $\endgroup$ – Cody Smith Aug 22 '14 at 18:25
  • $\begingroup$ @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. $\endgroup$ – Jean-Claude Arbaut Aug 22 '14 at 18:29
  • 1
    $\begingroup$ 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. $\endgroup$ – person27 Aug 22 '14 at 18:34
1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you very much, that makes since now! Can I assume that any number being treated as unsigned must have a leading zero (far left) in order to have enough range for it's possible result? $\endgroup$ – Cody Smith Aug 22 '14 at 19:09
  • $\begingroup$ If you mean what I think you mean, then yes. $\endgroup$ – David K Aug 22 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.