需要一些帮助,了解使用2&#x27的补充二进制加法/减法
如果a = 01110011,b = 10010100,我该如何添加?
ie:01110011 + 10010100 = 100000111
,虽然不是本质上是115 +(-108)= 7,而我得到的-249
编辑:我看到那是删除的,最高订单位(溢出)我得到了7,这就是我要寻找的东西,但是我没有得到为什么您不会额外的。
编辑**:好的,我弄清楚了。我认为没有溢出,因为[-128,127](8位)中有7个。取而代之的是,就像奥马尔(Omar)所暗示的那样,我应该从加法中删除“额外” 1。
If A = 01110011, B = 10010100, how would I add these?
i.e: 01110011 + 10010100 = 100000111
Though, isn't it essentially 115 + (-108) = 7, whereas, I'm getting -249
Edit: I see that removing the highest order bit (overflow) I get 7 which is what I'm looking for but I'm not getting why you wouldn't have the extra bit.
Edit**: Ok, I figured it out. There was no overflow as I had assumed there was because 7 is within [-128, 127] (8-bits). Instead, like Omar hinted at I was supposed to drop the "extra" 1 from addition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的计算正确,结果是正确的。
您说第二个数字为-108,因此您的两个数字都被解释为签名的8位值。因此,您还应该将结果解释为8位签名值,这就是为什么必须删除第9位的原因,因此结果为7(00000111)。
在真实的硬件中,例如8位CPU,例如所有寄存器宽度为8位,您只能存储结果的最低8位,这是7(00000111)。
在某些情况下,第9位也可以放入随身携带/溢流标志中,以免完全“掉落”。
Your calculation is correct and the result is correct.
You stated that the second number is -108, so both your numbers are interpreted as signed 8-bit values. Thus, you should also interpret your result as an 8-bit signed value, this is why the 9th bit must be dropped, and so the result is 7 (00000111).
On a real hardware, like an 8-bit CPU for example, as all the registers are 8-bit wide, you are only be able to store the lowest 8-bit of the result, which here is 7 (00000111).
In some cases, the 9th bit may also be put inside a carry/overflow flag so it's not completely "dropped".