0

I am having difficulty understanding why the following binary subtraction gives the result that it does. I keep getting a different answer. I am trying to compute 0.1-x such that x is 0.00011001100110011001100. The answer should be 0.000000000000000000000001100[1100]...(1100 keeps repeating) When i do it, I keep getting 1100 in the very beginning.

What am I not doing correctly?

Kyle Jones
  • 5,492
  • 1
  • 21
  • 30
  • What have you tried? What exactly is your answer? Why do you think the answer should keep repeating? – Adam Liss Apr 09 '12 at 20:56
  • How do you know that's the answer it "should be"? That's not close to the answer I get. – Rick Regan Apr 10 '12 at 01:59
  • Add together your 'answer should be' and your given `x`. Do you get `0.1` ? What does this say about your proposed 'answer'? – AakashM Apr 10 '12 at 08:12
  • Here's another hint that your expected answer is wrong: subtracting a finite fractional value from a finite fractional value will produce a finite fractional value. – Rick Regan Apr 10 '12 at 14:15

1 Answers1

0

I think that your expected answer is wrong. Here's my solution. I'll group the bits into nybbles so that it would look readable.

  0.1000 0000 0000 0000 0000 0000 <- added zero to the rightmost to fill in the nybble
- 0.0001 1001 1001 1001 1001 1000 <- added zero to the rightmost to fill in the nybble
_________________________________

Get the 2's complement of 0.0001 1001 1001 1001 1001 1000.

  1.1110 0110 0110 0110 0110 0111 (1's complement)
+ 0.0000 0000 0000 0000 0000 0001
_________________________________
  1.1110 0110 0110 0110 0110 1000 (2's complement)

Add the 2's complement to 0.1.

  0.1000 0000 0000 0000 0000 0000
+ 1.1110 0110 0110 0110 0110 1000
_________________________________
 10.0110 0110 0110 0110 0110 1000

Since the overflow is 1, disregard it. It just signifies that the final answer is a positive number since 0.1 is larger than 0.0001 1001 1001 1001 1001 1000. Therefore, the final answer is 0.011001100110011001101000.

ellekaie
  • 337
  • 1
  • 7
  • 21