How to represent -0 in binary

半城伤御伤魂 提交于 2020-01-06 16:20:05

问题


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 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?


回答1:


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'.



回答2:


+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.



来源:https://stackoverflow.com/questions/7067590/how-to-represent-0-in-binary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!