8 位处理器如何将 16 位数字的 2 个字节解释为单个信息?
假设 16 位编号。为 256。
因此,
字节 1 = 某个二进制数。
字节 2 = 某个二进制数
但是字节1也代表一个8位的数字(可以是一个独立的十进制数),字节2也是如此。
那么处理器如何知道字节1,2代表一个单一的数字。 256 不是两个单独的数字
Assume the 16 bit no. to be 256.
So,
byte 1 = Some binary no.
byte 2 = Some binary no.
But byte 1 also represents a 8 bit no.(Which could be an independent decimal number) and so does byte 2..
So how does the processor know that bytes 1,2 represent a single no. 256 and not two separate numbers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,处理器需要另一种长类型。我想您可以实现一个等效的软件,但对于处理器来说,这两个字节仍然具有单独的值。
处理器还可以具有特殊的整数表示和处理这些数字的机器指令。例如,现在大多数现代机器都使用二进制补码整数来表示负数。在二进制补码中,最高有效位用于区分负数。因此,二进制补码 8 位整数的范围为
-128 (1000 0000)
到127 (0111 111)
。您可以轻松地让最高有效位表示其他含义,例如,当 MSB 为 0 时,我们拥有从
0 (0000 0000)
到127 (0111 1111)
的整数;当 MSB 为 1 时,我们有从256 (1000 0000)
到256 + 127 (1111 1111)
的整数。这是高效还是优秀的架构是另一回事。The processor would need to have another long type for that. I guess you could implement a software equivalent, but for the processor, these two bytes would still have individual values.
The processor could also have a special integer representation and machine instructions that handle these numbers. For example, most modern machines nowadays use twos-complement integers to represent negative numbers. In twos-complement, the most significant bit is used to differentiate negative numbers. So a twos-complement 8-bit integer can have a range of
-128 (1000 0000)
to127 (0111 111)
.You could easily have the most significant bit mean something else, so for example, when MSB is 0 we have integers from
0 (0000 0000)
to127 (0111 1111)
; when MSB is 1 we have integers from256 (1000 0000)
to256 + 127 (1111 1111)
. Whether this is efficient or good architecture is another history.