简体   繁体   English

二进制减法-多余的数字?

[英]Binary Subtraction - Extra Digit?

Just messing around with Binary Subtraction using two's complement but I would like something explained. 只是用二进制补码弄乱了二进制减法,但是我想解释一下。

To perform 11 - 9 I first convert the 9 to a negative number by changing the 0's to 1's and 1's to 0's and then add 1. Then I add the negative number so it becomes 11 +(-9) 要执行11 - 9我首先将0更改为1,将1更改为0,然后将9转换为负数,然后将其加1。然后我将负数添加为11 +(-9)

Binary 二进制

 00001011
+11110111
---------
100000010

As I understand it, I just disregard the MSB so it becomes: 据我了解,我只是不理会MSB,因此它变成:

00000010

Why is it the case that I can drop the MSB? 为什么我可以放弃MSB?

Because you effectively added it first. 因为您首先有效地添加了它。

The invert/add one combo is equivalent to subtracting from a constant "one larger than allowed": 反转/加一组合等效于从常量“大于允许的整数”中减去:

100000000
 00001001
---------  -
 11110111

So you have changed 11 - 9 to 11 + (256 - 9) , which you can write as 11 - 9 + 256 to make it even clearer that you added that "extra bit" yourself in order to do the math, so now you have to drop it to get the result of the original expression. 所以,你已经改变了11 - 911 + (256 - 9)你可以写为11 - 9 + 256 ,使之更加清晰,你还说,“额外位”自己为了做数学题,所以现在你必须删除它以获得原始表达式的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM