GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An 8-bit two's complement adder computes 3x as (x + x) + x for every x from −128 to 127, setting the overflow flag V separately on each addition. For how many x do BOTH additions set V, and for how many x does the final 8-bit result differ from the true value 3x?

  1. A. 43 and 171
  2. B. 0 and 128
  3. C. 21 and 171
  4. D. 0 and 171

Correct answer: D. 0 and 171

The first addition overflows when 2x leaves −128..127, i.e. x ≥ 64 or x ≤ −65 (128 values). Its wrapped result 2x ∓ 256 then has the opposite sign to x, and adding numbers of opposite signs can never overflow, so both additions never overflow together: 0. The final result is correct exactly when 3x fits, −42 ≤ x ≤ 42 (85 values), so 256 − 85 = 171 results are wrong (128 with the first V set, 43 with only the second V set).

More Digital Logic questions

Exams that ask this topic