需要一些帮助,了解使用2&#x27的补充二进制加法/减法

发布于 2025-02-07 08:01:53 字数 462 浏览 2 评论 0原文

如果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 did this: enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2025-02-14 08:01:53

您的计算正确,结果是正确的。

您说第二个数字为-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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文