Answers to Two's Complement Exercises

  1. The largest number that can be represented in 10-bit two's complement is 29-1 = 511; the smallest number is -29 = -512.

    1.    0101011010   34610
        +1001000101  -44310
        ------------  ---
         1110011111   -9710    no overflow
      
      Explanation:
      -----------
      0101011010: This is positive (leftmost bit is 0), so just interpret this
      as a base 2 number => 34610.
      
      1001000101: This is negative (leftmost bit is 1), so take the two's complement
      and then negate the base 2 interpretation of the result:
      
         Start with 1001000101 and flip all bits to the left of the rightmost 1
       
      to get  0110111011 = 44310, so original number is -443.
      
      Add bits to get 1110011111, then interpret it like the second number above,
      since it is negative.  This gives -97, the correct result; no overflow
      occurred.
      
      

    2. 0101011010 34610 +0011000110 19810 ------------ --- 1000100000 -48010 overflow Explanation: ----------- 0101011010: This is positive, so interpret it as a base 2 number => 34610. 0011000110: This is positive, so interpret it as a base 2 number => 198.10. Add bits to get 1000100000. This is negative, so take two's complement, interpret as a base 2 number and negate => -480. The sum of two positive numbers cannot produce a negative number, so overflow must have occurred. Furthermore, the correct sum 544 is too large to fit in 10-bit twos complement so the sum overflows.

    3. 1001000101 -44310 +1111011110 -3410 ------------ --- 1000100011 -47710 no overflow

    4. 1001000101 -44310 +1101100000 -16010 ------------ --- 0110100101 42110 overflow

    5. 0101011010 34610 +1111011110 -3410 ------------ --- 0100111000 31210 no overflow

  2. False. A 1 carried out of the leftmost position doesn't mean anything; overflow may or may not have occurred. Note that it will always happen when you add two negatives, and may happen when you add a negative and a positive.

  3. No. The result will always be closer to 0 than either number, and so cannot produce overflow.