关于数字表示
如何找到我所在系统的数字表示形式?
How do I find the representation of a Number for the system I am on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何找到我所在系统的数字表示形式?
How do I find the representation of a Number for the system I am on?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
AFAIK 每台现代计算机在表示数字时都使用二进制。已经用其他类型的计算机进行了实验,但它们未能与二进制竞争。
然而,他们正在使用量子计算机,其工作方式完全不同,并以完全不同的方式表示数字。
AFAIK every modern computer uses binary when representing a number. Experiments have been made with other kind of computers, but they have failed to compete with binary.
However, they are working a quantum computers which work completely different and represent numbers on a completely different way.
通常的方法是将数字存储在内存中,然后检查内存。
对于
易失性
表示歉意;我不记得严格的别名规则,并且现在不想查找它们。The usual way is to store the number in memory, and then inspect the memory.
Apologies for the
volatile
; I do not recall strict aliasing rules and don't want to look them up right now.了解符号表示实际上很简单。查看结果
一旦您了解了 C 允许的三种不同的符号表示如何工作(参见例如 Acme 的答案),您将轻松计算出它们的此类表达式的值。
To know the sign representation is actually quite simle. Look at the result of
Once you have understood how the three different sign representations work that C allows (see eg. Acme's answer), you will easily work out the values of such an expression for them.
诸如表示(字大小、二进制补码与符号大小)和字节序等架构问题最好通过硬件和/或操作系统和/或编译器文档来回答。
您可以使用类型双关来检查值的各个字节:
不过,对于大端与小端,您可以执行
“Better to RTM”之类的操作。
Architectural questions such as representation (word size, two's- vs. one's-complement vs. sign-magnitude) and endianness are best answered with hardware and/or OS and/or compiler documentation.
You can use type punning to examine the individual bytes of a value:
For big- vs. little-endian, you could do something like
Better to RTM, though.