Electrical – Overflow detection for the given case

digital-logic

Two 2's complement numbers having sign bits x and y are added and sign bit of result is z.Then occurence of overflow is indicated by which boolean function?
I believed that overflow occurs when the XOR of the sum and carry is 1 ,there is overflow,else no overflow.Keeping this in mind,I came up with the following truth table:

X Y Z Overflow

0 0 0 0

0 0 1 1

0 1 0 1

0 1 1 0

1 0 0 1

1 0 1 0

1 1 0 0

1 1 1 1

Is this table correct?

Best Answer

When can an overflow happen?

  • Adding a positive and a negative number yields a number in between them (lower border inclusive), thus no overflow is possible.
  • Adding two positive numbers will always result in a positive number.
  • Adding two negative numbers will always result in a negative number.

-> An overflow is only possible when both summands share the same sign.

Can an overflow wrap around more than once?

In a n-bit 2's complement number,

  • the maximum number is \$2^{n-1}-1\$. Adding two of them yields: $$2\cdot(2^{n-1}-1)=2^n-2=-2$$
  • the minimum number is \$-2^{n-1}\$. Again adding two of them: $$2\cdot(-2^{n-1})=-2^n=0$$

-> In case of an overflow the result will be always negative for positive summands and positive for negative summands.

Conclusion

An overflow has happened if, and only if, both summands have the same sign and the result has the other sign.