Jump to content
MakeWebGames

unsigned binary math


cardboardtoast
 Share

Recommended Posts

Hello all! (and yes this is a hw question, before anyone asks, Im looking for help, not the answer)

I have to subtract two unsigned binary numbers, with the second larger than the first.

01011110

-10110110

-------------

I have gotten most of the answer:

X0101000, but I dont know what to do for the last number. I have 0 - 1, and nowhere to borrow from. What am I supposed to do in this situation? I dont know if the fact that this is supposed to be unsigned changes anything? Any help is appreciated.

Edited by cardboardtoast
Link to comment
Share on other sites

Ok, so odd issue here. Your final answer makes sense (94-182 = -88), but the grading program flagged it as wrong, claiming that the second step's answer: 1010 1000 (168) was correct. I only did the complement once in all of the other questions, and it said correct. Is there a reason why one would NOT do the complement twice?

Thanks for the quick response!

Link to comment
Share on other sites

Funny you should bring up assembler, because this is for an assembly language class (the prof is going over a little about how a computer actually does the math) :p

Ok, so I believe I have figured out the answer. Because this was defined as a system that uses "unsigned (ie positive)" numbers only and ignores all negatives, it does not take the possibility of a negative answer into account (as it cannot have a negative at all). Using only 1 two's complement, I can get the correct answer to any subtraction that will result in a positive answer:

just to be easy: 8-3 = 5 (I did a few more on paper, but yeah, that would make this a big post)

8: 0000 1000
3: 0000 0011
------------

Doing the two's comp only once gets:

0000 1000
1111 1101
-----------
0000 0101 = 5

So if you dont ever think you will have a negative number, this is all that is needed. Because my problem was for "unsigned numbers" only, I did not have to check if the problem would result in a negative answer (which is impossible), and could stop at that step. As you pointed out, the next step involved putting a negative sign in front of the answer, which I cannot do as it will be rejected (and positive 88 would be wrong anyways). Well, thats all I can think of to explain it, I will see if I can ask in class, but that will be a while.

Once again, thanks for your help and the quick responses Octarine!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...