需要帮助添加二进制补码符号

Need help adding with Twos Complement notation

我对二进制补码有点困惑。我评论了 What is “2's Complement”?.

我正在尝试添加 -2 + -3 = -5。这是我的思考过程:

+2 = 0010
-2 = 1110 # in twos complement

+3 = 0011 
-3 = 1101 # in twos complement

 1101
+1101
-----
10010 # What is this?

我知道 -5 在二进制补码中是 1011。但是我不确定在上面的示例中添加 -2 + -3 时我做了什么。

如能解释添加 -2 + -3 的过程,将不胜感激。感谢您的协助!

在4位2的补码中-2为1110+3为0011所以

11110  carry 
 1110  -2
+0011  +3
 ----
10001  which is 0001 or simply 1 ignoring the carry in bit 5

从右到左逐步完成流程:

  1. 1 + 0 结果是没有进位的 1

  2. 1 + 1 结果为 0,进位为 1

  3. 1 + 0 + 进位 1 结果 0 进位 1

  4. 1 + 0 + 1 的进位结果为 0,进位为 1

  5. 只需进位 1 就可以得到 1,没有其他可进位的东西

有关参考,请参阅维基百科关于 2 的补码的文章,特别是 https://en.wikipedia.org/wiki/Two%27s_complement#Addition. There are a number of online 2's complement calculators to help with conversions and one of them is at http://www.exploringbinary.com/twos-complement-converter/

中关于加法的部分

如果您想了解 -3 + -3 是如何完成的,请告诉我,因为这正是您尝试过的。这是一个类似的过程,但一定要从足够大的位长度开始,以避免在进位行中最左边的两位具有不同值时确定的溢出。