Skip to content
BetterDL

Signed overflow

Also called: two's complement overflow, signed arithmetic overflow

Overflow for two's complement numbers: adding two values with the same sign gives a result with the opposite sign. Detected as carry into MSB ≠ carry out.

Signed overflow happens when the true result of a twos complement operation is outside the signed range, so the stored bits read as the wrong number, with the wrong sign.

The sign rule for addition:

  • two positives giving a negative: overflow
  • two negatives giving a positive (or zero): overflow
  • a positive plus a negative: never overflows, because the result lies between the two operands

The hardware rule: compare the carry into the MSB column with the carry out of it. If they differ, it's signed overflow. In an n-bit adder that's V = Cₙ ⊕ Cₙ₋₁, a single XOR gate. The two rules always agree.

Why? With two positive inputs, the sign column adds 0 + 0 + carry-in, so the result's MSB equals the carry-in, and a carry-in of 1 makes the result look negative. With two negatives, the column adds 1 + 1 + carry-in, which always carries out, and a carry-in of 0 leaves the result looking positive. With mixed signs, the carry-in and carry-out are always equal.

For subtraction A − B, apply the sign rule to the numbers the adder actually adds, A and −B. Processors record the result in the overflow flag V.

C4C3V

Worked examples

Example

7 + 2 in 4 bits (overflow)

0111 + 0010. The signed range is −8 to 7, so 9 can't fit.

  1. 1.

    Bit 0: 1 + 0 = 1.

  2. 2.

    Bit 1: 1 + 1 = 10₂. Write 0, carry 1.

  3. 3.

    Bit 2: 1 + 0 + 1 = 10₂. Write 0, carry 1. This is the carry into the MSB.

  4. 4.

    Bit 3: 0 + 0 + 1 = 1, carry-out 0.

  5. 5.

    Carry in 1, carry out 0: they differ, so signed overflow. 1001 reads as −7.

Example

−3 + (−4) in 4 bits (no overflow)

1101 + 1100.

  1. 1.

    Bit 0: 1 + 0 = 1. Bit 1: 0 + 0 = 0.

  2. 2.

    Bit 2: 1 + 1 = 10₂. Write 0, carry 1 into the MSB.

  3. 3.

    Bit 3: 1 + 1 + 1 = 11₂. Write 1, carry-out 1.

  4. 4.

    Carry in 1, carry out 1: equal, so no overflow. 1001 = −7, which is right.

Common mistakes

  • Using the carry-out alone to judge signed results.

  • Expecting a positive plus a negative to overflow. It never can.

  • Applying the sign rule to the original B in a subtraction, instead of to −B.

Practice Signed overflow

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Signed overflow is taught in Number Systems and Adders and ALUs.