use 2's complement to add numbers of like signs. (a)48+23 (b)-48-23

时间:2018-03-25 19:45:25

标签: binary

I just learnt the concept of two's complement. It is useful in the subtraction of binary numbers. But in my college booklet i have been asked to solve 48+23 and -48-23 using 2's complement. What is the logic behind this and how to proceed with this question?

1 个答案:

答案 0 :(得分:0)

The key insight is that negative numbers are not merely conveniently represented by two's complement, but the scheme actually preserves the properties of addition and subtraction naturally as a result of the encoding itself. That is:

  • Bit patterns end up identical when you subtract positive numbers or add equivalent negative numbers; and when you add positive numbers or subtract equivalent negative ones
  • The signum rolls over automatically in either direction: that is, negative numbers extend 'naturally' to 0 and thence to positive numbers by counting up

These properties make working (i.e. arithmetic) using this encoding a lot easier than, say one's complement.

Finally, for a fixed length two's complement bit string, the number of available negative numbers is always exactly one larger than the number of available positive numbers.