2

I was solving a binary subtraction and got stuck at a point. I am unable to understand how to subtract a larger number from a smaller number.

My operands are 0.111000*2^-3 and 1.0000*2^-3.

I have easily subtracted the fractional part but when coming to the MSB, I dont know how to do it. From where should I borrow to perform the operation. I know subtracting 1 from 0 requires a borrow and it turns sign bit to negative. But here, the storing is not under concern. My problem is with the operation itself. Could anyone explain wats the result and how to perform it??

Thanks

user1322915
  • 1,211
  • 2
  • 13
  • 10
  • Need to ask a couple of things to make sure everyone is on the right page. When talking about math, `binary` usually refers to integer values, but it sounds like you are talking about floating point. If you are, there are several different version of floating point out there, with [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point) being the most common. – Jeremy J Starcher Sep 25 '12 at 00:47
  • @ Jeremy J Starcher, I am talking about the IEEE 754 standard. In fact, my original problem too is subtracting 2 double precision numbers. But to make it more simpler, i have just given the first 7 bits. Anyways the rest are 0's in both the numbers – user1322915 Sep 25 '12 at 00:56
  • In that case I'm going to point you towards my favorite tool here at Stack Overflow -- the search option. This might help you: http://stackoverflow.com/questions/591046/implementing-floating-point-subtraction – Jeremy J Starcher Sep 25 '12 at 00:58

2 Answers2

2

Very late, but had the same question so putting this here for others, having the same problem.

If your problem lies only at the fraction part, you could try this method:

  1.000
- 0.111
-------

Step 1: Add sign bit of both binary numbers so you can add.

 0 1.000
 1 0.111
 -------  +
 1 1.111

Now invert and add one to convert from 2's complement to sign-magnitude:

1 1.111 -> 0.001
Armannas
  • 83
  • 12
1

Here is a great example that may help you:

http://sandbox.mc.edu/~bennet/cs110/pm/sub.html

If doing this programmatically, you can cheat and see which is larger before you perform the subtraction (which is what I do).

Dave
  • 1,823
  • 2
  • 16
  • 26
  • But from the link you have given, there is no example showing a larger number being subtracted from a smaller one. Could you please explain how it takes place? – user1322915 Sep 25 '12 at 00:53