Perform the indicated operation of the numbers, which are in two's-complement representation. Check your results by converting all numbers to decimal. Indicate overflow and carryout.

(a) 10010111-00111100

1001 0111 (151)
- 0011 1100 (60) ---->+ 1100 0100 (-60)

  • I used two's complement to change (60) to (-60).

10010111 (151)
+ 11000100 (-60)
= 1 0101 1011

  • The answer is in 9 bits, while the rest are in 8 bits.
  • The range is -128 to 127 : -(2^(8-1)) to (2^(8-1)-1)

Is this a carry out? Is this an overflow? I know that it's a carry out because we are adding a bit into the sign. But is this considered an overflow? Discarding the 1 on the left-most side, we convert the answer to (91) in decimal, which matches with (151) - (60) = (91).

I at first considered this NOT an overflow, because (91) is in range. However, I am not sure if I am supposed to take into account the carry out of 1. The 1 also confuses me because the answer is positive and not negative. Am I supposed to discard the 1? Is this signed, meaning that the answer is negative? But the answer is supposed to be positive?? I'm just getting a little more confused the more I think about it.

(I know I could have just subtracted normally, but I wanted to do it this way)

  • $\begingroup$ In two's complement it's really easy to tell whether overflow happens during addition: if the carry-out is different from the carry-in to the sign bit, then overflow has occurred. Otherwise it hasn't. $\endgroup$
    – Arthur
    Mar 2 '18 at 7:23

Since we have 2's complement and 8 bits, the leftmost bit is the sign bit. This means 1001 0111 is NOT 151, but rather -105.

To continue the math:

1001 0111 (-105) - 0011 1100 (60) ---->+ 1100 0100 (-60)

Then as you did before, 10010111 (-105) + 11000100 (-60) = 1 0101 1011

Since we are working in 8bits,0101 1011 is 91 in decimal.

Note that overflow applies when we work with signed numbers and occurs when we add to the sign bit, while carry out applies when we work with unsigned number and occurs when the bits "fall" off the left.

Therefore, in this case, we do have overflow since the sign bit has been altered.

In general, the term carry out doesn't really concern signed number, but in the interest of your problem, you could say there is carry out since you do have one bit that couldn't be represented on the left.

  • $\begingroup$ But the answer's decimal conversion doesn't match. So (-105) + (-60) = (-91)? $\endgroup$
    – Crynical
    Mar 2 '18 at 9:15
  • $\begingroup$ Yes and No. I am claiming if you do the 2's complement computation, (-105) + (-60) = 91 (note the positive). Clearly it doesn't match real arithmetic, and therefore we have an overflow. $\endgroup$
    – Mong H. Ng
    Mar 2 '18 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.