开发者

How to represent -0 in binary

This question concerns converting a floating point number that is less than abs(1) and negative to 32.32 format, for example: -0.1234.

When this is converted to 32.32, the integer portion and fractional portion 开发者_Python百科are separated into the upper and lower 32 bit words, respectively. In this example above, the upper 32-bits will hold -0, while the lower will hold .1234, both converted to binary.

So the question is, in this case, how does one properly represent the -0 value in binary?


It depends.

  • Two's complement, there is no such thing as -0.
  • One's complement, -0 is represented by all '1's.
  • Sign-magnitude, -0 is represented by a sign bit of '1', and all other bits as '0'.


+0 == 0 == -0 for practical purposes of programming. In this case, you would have to figure out how negative numbers are being handled but the underlying system. ( Generally either two's complement or sign bit ) and monkey with that accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜