简体   繁体   English

减去负2的补数

[英]subtracting a negative 2's complement

I have two 2's complement signed binary numbers and want to subtraction them (assuming an 8-bit subtractor) 我有两个2的补码有符号二进制数,并想将它们相减(假设使用8位减法器)

1001 0110 1001 0110

1000 0001 1000 0001

what would be the operation to find the difference and why/whynot is there an overflow 找出差异的操作是什么,为什么/为什么没有溢出

to get the difference between 2 numbers you have to subtract them: 要获得2个数字之间的差,您必须将它们相减:
1001 0110b = -106
1000 0001b = -127
so -106 - (-127) = 21 因此-106 - (-127) = 21

you can also do that in binary: 您也可以用二进制代码执行此操作:

 1001 0110b
-1000 0001b
     =
 0001 0101b

another method is: ab = a+(-b) , so you have to make the 2's complement of the second number. 另一个方法是: ab = a+(-b) ,因此您必须对第二个数字进行2的补码。 So 1000 0001b becomes 0111 1111b . 因此1000 0001b变为0111 1111b

  1001 0110b
 +0111 1111b
      =
1 0001 0101b

the first 1 doesn't count because it's a 8bit number, so the result is also 0001 0101b which is 21 in decimal. 前一个1不计数,因为它是8位数字,因此结果也是0001 0101b ,即十进制21。

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

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