Search code examples
logical-operators

What does this logic equation of overflow mean?


here is a paragraph from the textbook:

When two's complement numbers are added or subtracted...Overflow is defined as the situation in which the result of an arithmetic operation lies outside of the number range that can be represented by the number of bits in the word...

The logic function that indicates that the result of an operation is outside of the representable number range is: OVR = Cs XOR Cs+1 where Cs is the carry-in to the sign bit and Cs+1 is the carry-out of the sign bit.

I assume that by saying "sign bit" the author means the top bit. Now assume we have a 4-bit adder, 1100+1100, which leads to an overflow. The carry-in to the sign bit is 1 and the carry-out is also 1. This seems to contradict the formula. Where is the mistake?


Solution

  • (Please read the comments of the original question for more details)

    In fact, as Raymond Chen mentioned, 1100+1100 does not cause an overflow, as the result still firs in a 4-bit signed value.

    If we instead use 1000+1111, then the resulting -9 is indeed an overflow and we can observe the carry-in as 0 and carry-out as 1 for the sign-bit.