gpt4 book ai didi

assembly - 如何将大于 128 的数字存储在有符号的一字节整数中?

转载 作者:行者123 更新时间:2023-12-03 06:32:05 26 4
gpt4 key购买 nike

我正在读《汇编语言的艺术》一书。我在那里看到了这一段。

If the H.O. bit is zero, then the number is positive and is stored as a standard binary value. If the H.O. bit is one, then the number is negative and is stored in the two’s comple-ment form. To convert a positive number to its negative, two’s complement form, you use the following algorithm:

  1. Invert all the bits in the number, i.e., apply the logical NOT function.

  2. Add one to the inverted result.

    For example, to compute the eight bit equivalent of -5:

    0000 0101  Five (in binary)   
    1111 1010 Invert all the bits.
    1111 1011 Add one to obtain result.

这里我想知道0000 0101是否是小数点5,1111 1011是-5,那么我们如何表示251?不就是1111 1011吗?计算机如何区分-5和251

最佳答案

当用 8 位表示有符号数时,第 8 位(HO 位)是符号位。因此只能使用7位来存储数字的值。 8 位有符号数的范围是 -128..127。 251无法表示,除非使用超过8位。

关于assembly - 如何将大于 128 的数字存储在有符号的一字节整数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3908143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com