[英]Two's Complement arithmetic of 2 negative numbers
I need to calculate (-13)(base 10) + (-14)(Base 10) using representation of complement 2's in 6 bits. 我需要使用6位补码2的表示来计算(-13)(基数10)+(-14)(基数10)。 I read Wikipedia:Two's complement how to do it.
我阅读了Wikipedia:Two的补码用法。 I converted 13 to (-13):
10011
and converted 14 to (-14): 10010
and I just did the math normally and got: 100101, but the system that is checking my answers keep telling me it is wrong and I don't understand why. 我将13转换为(-13):
10011
,并将14转换为(-14): 10010
然后我正常地进行了数学运算并得到:100101,但是检查我的答案的系统不断告诉我这是错误的,我没有不明白为什么。
If you use 6 bits for the results, you should use 6 bits when converting to two's complement. 如果对结果使用6位,则转换为二进制补码时应使用6位。
13 is 001101
in base 2, so -13 is 110011. 14 is 001110
, so -14 is 110010
. 13是基数2中的
001101
,因此-13是110011.14是001110
,因此-14是110010
。 Adding them: 添加它们:
110011
+ 110010
--------
000101
The result is 5. 结果是5。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.