简体   繁体   English

小数二进制减法

[英]fractional binary subtraction

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.我正在尝试计算 0.1-x,使 x 为 0.00011001100110011001100。 The answer should be 0.000000000000000000000001100[1100]...(1100 keeps repeating) When i do it, I keep getting 1100 in the very beginning.答案应该是 0.000000000000000000000001100[1100]...(1100 不断重复)当我这样做时,我一开始就一直得到 1100。

What am I not doing correctly?我做错了什么?

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.我会将这些位分组为 nybbles,以便它看起来可读。

  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 .获取0.0001 1001 1001 1001 1001 1000的 2 的补码。

  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 .将 2 的补码添加到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.由于溢出为1 ,请忽略它。 It just signifies that the final answer is a positive number since 0.1 is larger than 0.0001 1001 1001 1001 1001 1000 .它只是表示最终答案是正数,因为0.1大于0.0001 1001 1001 1001 1001 1000 Therefore, the final answer is 0.011001100110011001101000 .因此,最终答案是0.011001100110011001101000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM