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?
-> 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,
-> 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.