十六进制数有负数吗?
十六进制数有负数吗?如果是的话怎么办?
对于二进制文件,您将有有符号和无符号。
如何用十六进制表示它们?我需要这个来进行我即将开始的十六进制例程。
Are hexadecimal numbers ever negative? If yes then how?
For binary you would have signed and unsigned.
How would one represent them in Hex? I need this for a hex routine I am about to embark upon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的。例如,您将拥有以下带符号的 32 位二进制和十六进制表示形式:
如您所见,负数的十六进制表示形式与二进制表示形式直接相关。
Yes. For example you'd have the following representations in signed 32-bit binary and hex:
As you can see, the Hex representation of negative numbers is directly related to the binary representation.
数字的高位决定它是否为负数。例如,int 的长度为 32 位,因此如果第 31 位为 1,则其值为负。现在,如何显示该值(无论是十六进制还是十进制)并不重要。所以像这样的十六进制值
都是负数,因为最高位设置为1
The high bit of a number determines if it is negative. So for instance an int is 32 bits long, so if bit 31 is a 1 it is negative. Now how you display that value be it hexadecimal or decimal doesn't matter. so the hex values like
are all negative, because the top bit is set to 1
是的,他们可以。它与二进制的解释方式相同(有符号与无符号)。
Yes they can be. It's the same as binary as to how you interpret it (signed vs unsigned).
您可以采用二进制有符号和无符号形式,然后以十六进制表示它们,就像任何二进制数一样。
You would take the binary signed and unsigned forms then represent them in hex as you would any binary number.
一方面,为什么不呢 - 它只是一个位置数字系统,就像十进制一样。
另一方面,它们通常使用十六进制表示法来推断底层的位模式 - 如果数字被解释为无符号,那就更简单了。
所以答案是 - 这是可能的,数学上正确且内部一致,但违背了十六进制符号最常见的目的。
On one hand, why not - it's just a positional numeric system, like decimal.
On the other hand, they normally use hex notation to deduce the underlying bit pattern - and that is much more straightforward if the number is interpreted as unsigned.
So the answer is - it's possible, mathematically correct and internally consistent, but defeats the most common purpose of hex notation.
在 Java 中,这些是
Integer
数据类型的界限:In Java, these are the bounds of the
Integer
data type: