您应该将它们视为具有无限多个 1 位。抽象地说,二进制补码 https://en.wikipedia.org/wiki/Two's_complement二进制表示has无限多个 1;并不是说可以根据需要添加更多的 1,而是那些 1已经数字表示方式的一部分。
事实上,那些无限多的位实际上并未存储在内存中,这是一个实现细节,因此,当您考虑这一点时,您应该忽略内存的限制,直到遇到以下情况:you是必须编写实现的人。如果您只是想从概念上理解这一点,则不需要考虑诸如后备位之类的事情,而且我认为这不一定有帮助。
二进制数表示 2 的幂之和,例如:
110012 = 24 + 23 + 0 + 0 + 20
数字 -1 由无限的 1 序列表示,向左无限延伸:
...11112 = ... + 23 + 22 + 21 + 20
这对于通常意义上的无穷级数来说是无稽之谈,但有充分的理由将结果定义为 -1。最直观地吸引人的原因是当你按照加法算法将 1 添加到它时会发生什么:
...111111111
+ 1
――――――――――――
= ...000000000 (result)
――――――――――――
...11111111 (carry)
In the rightmost column you have 1 + 1 which is 2, or 102 in binary, so you write a 0 and carry a 1 to the next column left. Then in that column you have a 1 plus the carried 1, so you write 0 and carry another 1... and so on, ad infinitum. The result has a 0 in every position. Therefore, ...111112 must have represented -1 because we followed the algorithm to add 1, and we got a representation of 0.
If that's not satisfying enough, then there are other reasons that ...111112 ought to be interpreted as a representation of -1:
- 无限和 1 + 2 + 4 + 8 + ... 是一个几何级数;具有恒定比率 r 的几何级数的公式为 1/(1 - r)。该公式仅适用于 -1
- 实际上无限和 1 + 2 + 4 + 8 + ...does收敛到-12-进范数 https://en.wikipedia.org/wiki/P-adic_number.
- 结果-1也可以通过其他定义获得,包括欧拉求和 https://en.wikipedia.org/wiki/Euler_summation, and 正如维基百科所述 https://en.wikipedia.org/wiki/1_%2B_2_%2B_4_%2B_8_%2B_%E2%8B%AF任何求和方法都是stable and linear将此和与结果 ∞ 或 -1 相关联。
我提到这些还因为它们暗示某些性质对于算术仍然成立。应用“无穷大”的加法、减法和乘法的常用算法可以给出符合算术常用属性(如结合性、交换性和分配性)的合理结果。