Is this an overflow arithmetic calculation?

孤人 提交于 2019-12-02 06:53:49

No, it isn't overflow - the overflow resulting from the addition of 2 1's in the MSB must just be discarded. From Wikipedia

To get the two's complement of a binary number, the bits are inverted, or "flipped", by using the bitwise NOT operation; the value of 1 is then added to the resulting value, ignoring the overflow which occurs when taking the two's complement of 0.

So in your example

185 10111001
122 01111010 -

Taking the 2's complement of 122 (One's complement +1)

01111010 => 10000110

Adding:

10111001 185
10000110 +(-122)
--------
00111111 (63)

=63

The overflow is ignored.

There are however rules for detecting overflow after doing the 2's complement :

  • If the sum of two positive numbers results in a negative result
  • If the sum of two negative numbers results a positive result
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!