1
$\begingroup$

So I am having a bit of an issue. First, what is the difference between doing an unsigned binary integer subtraction and doing a signed integer subtraction? I think that is what is confusing me. For an unsigned integer, I was told that you have to add a 0 next to the most significant bit (I may be wrong), but I don't feel comfortable with that. After watching a couple of videos on youtube, I tried to the subtraction.

0011 0001 – 1010 1011

My thought process: I decided to take 1010 1011 and do one's complement and then two's complement and then add it to 0011 0001.

Click here to see my work

$\endgroup$
1
$\begingroup$

In unsigned binary, all numbers are positive and you can't subtract a larger one from a smaller one. If we translate your problem to base $10$ we get $49-171$ which does not have an answer. For unsigned binary you just do subtraction like you learned in school except in base $2$, borrowing when necessary. So if we want to do your problem in reverse, $171-49$ we get $$\begin {align}1010 1011&\\ \underline {-0011 0001}& \\01111010& \end {align}$$ where we borrowed in the $2^5$ place and it carried to the next two.

$\endgroup$
  • $\begingroup$ Oh okay that makes sense. How about if they are signed though? I want to know the differences. $\endgroup$ – user6134432 May 25 '16 at 2:41
  • $\begingroup$ For signed binary, you need to resolve the signs. If you have $a-b$ and $b$ is negative (check the sign bit), you flip the sign bit and add. If you have $a+b$ and $a$ is negative, you do $b-a$ and so on. This is why computers use two's complement-you don't have to worry about it. $\endgroup$ – Ross Millikan May 25 '16 at 3:37
  • $\begingroup$ Oh okay I see. My other concern is with the unsigned subtraction with this one. I took the 0011 0001, flipped the bits, and added 1, and you get 1100 1111. Then, I did 1010 1011 + 1100 1111 = 1 0111 1010, which is what you have except I think you ignored the bit. Wouldn't this be overflow since carry in (0) does not equal carryout (1)? $\endgroup$ – user6134432 May 25 '16 at 3:57
  • $\begingroup$ You are confusing twos complement and signed binary. Signed binary just has a sign bit but leaves the rest of the number the same, so $-1=1000 0001$ Twos complement inverts all the bits and adds one. It has the advantage that you can do the same arithmetic for positive and negative numbers, which is not true for signed binary or ones complement. Please be clear which you are talking about. $\endgroup$ – Ross Millikan May 25 '16 at 4:48

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.