GATE / CS ARCHIVE

SIMILAR QUESTIONS / DIGITAL LOGIC

Detect signed fixed-width overflow

7 questions solved the same way, newest first. Back to Digital Logic

How these are solved

Decode the specified signed representation and compare exact arithmetic with its representable bounds; for two’s complement also apply equal-operand-sign/opposite-result-sign or carry-into XOR carry-out.

1 mark · MSQ
Report issue

Overflow in sign-magnitude arithmetic

Number Systems & Computer Arithmetic

Question 22, GATE 2026: X and Y are 8-bit sign-magnitude words 10110100 and 01001100. Which results cannot be represented as an 8-bit sign-magnitude Z: A X+Y; B X−Y; C −X+Y; D −X−Y?
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C

Step through it (8 steps)

Givens and goal

X and Y are 8-bit sign-magnitude words 10110100 and 01001100. Which results cannot be represented as an 8-bit sign-magnitude Z: A X+Y; B X−Y; C −X+Y; D −X−Y?

Approach

Decode sign and magnitude separately, calculate the mathematical result of each operation, and compare with the representable interval.

Step-by-step solution

1. One bit is the sign and seven bits hold the magnitude. The largest magnitude is 27−1=127, so representable values lie from −127 to +127. There are separate encodings of zero; there is no −128 value.
2. X has sign 1 and magnitude 0110100₂=32+16+4=52, so X=−52. Y has sign 0 and magnitude 1001100₂=64+8+4=76, so Y=+76.
3. A gives X+Y=−52+76=24, which is representable. B gives X−Y=−52−76=−128, below the minimum, so it overflows.
4. C gives −X+Y=52+76=128, above the maximum, so it overflows. D gives −X−Y=52−76=−24, which is representable.
5. Select B and C. The raw bit patterns must not be interpreted as two’s-complement values: that different representation would assign a different value to X and a different representable lower bound.

Original paper, page 17 · Answer key

1 mark · MSQ
Report issue

Four-bit signed overflow

Number Systems & Computer Arithmetic

Question 28, GATE 2026: Use 4-bit two’s-complement integers N1=1011, N2=1101, N3=1010, N4=1001. Which operations overflow? A N1+N2; B N2+N3; C N3−N4; D N1+N4.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, D

Step through it (4 options)

Givens and goal

Use 4-bit two’s-complement integers N1=1011, N2=1101, N3=1010, N4=1001. Which operations overflow? A N1+N2; B N2+N3; C N3−N4; D N1+N4.

Approach

Convert operands to signed values and compare exact results with the representable interval.

Step-by-step solution

1. Four-bit two’s complement represents −8 through 7. A bit pattern with leading 1 has signed value equal to its unsigned value minus 16. Thus N1=11−16=−5, N2=−3, N3=−6, N4=−7.
2. A gives −5+(−3)=−8, exactly the lower endpoint and therefore representable as 1000. Merely having a carry out does not establish signed overflow.
3. B gives −3+(−6)=−9, below −8. The retained four bits would be 0111, a positive 7, so signed overflow occurs. C gives −6−(−7)=1, represented by 0001, so it is safe.
4. D gives −5+(−7)=−12, also below the range. Its wrapped pattern is 0100, positive 4. Therefore B and D overflow.
5. For addition of same-sign operands, a changed result sign is a convenient equivalent test, but checking the exact mathematical result also handles the subtraction correctly.

Original paper, page 21 · Answer key

1 mark · MCQ
Report issue

Check signed arithmetic against its range

Number Systems & Computer Arithmetic

Question 13, GATE 2024: Signed integers use five-bit two's complement. A is 01010 and B is 11010. Which operation overflows or underflows this representation? A A+B; B A−B; C B−A; D 2B.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step through it (4 options)

Approach: Decode the operands as signed values, perform ordinary integer arithmetic, and compare each mathematical result with the representable interval.
1. With five bits, two's complement represents −2⁴ through 2⁴−1, namely −16 through 15.
2. A has leading bit 0, so A=10. B has unsigned value 26 and leading bit 1, so its signed value is 26−32=−6.
3. The four results are A+B=4; A−B=16; B−A=−16; and 2B=−12.
4. Only 16 falls outside [−16,15]. Its five-bit pattern would wrap to 10000, which represents −16 rather than the intended positive 16.
Answer: B. The value −16 in option C is exactly the valid lower endpoint, not an underflow. Two's complement has one more negative value than positive nonzero values.

Original paper, page 9 · Answer key

1 mark · MCQ
Report issue

Number Systems & Computer Arithmetic

Question 18, GATE 2022: Four-bit registers use two's complement. Which sum overflows? A 1011+1110; B 1100+1010; C 0011+0100; D 1001+1111.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step through it (4 options)

Four-bit two’s-complement integers range from −8 through 7. The sums in A, C, D are −7, 7,−8 and are representable. B computes −4+(−6)=−10, outside the range, so it overflows. Thus B.

Decode a bit pattern with leading 1 by subtracting 16 from its unsigned value. Thus A is −5−2=−7; B is −4−6=−10; C is 3+4=7; D is −7−1=−8. B wraps to 0110 (+6), revealing the sign reversal for a negative-plus-negative sum.

Original paper, page 14 · Answer key

1 mark · MCQ
Report issue

Number Systems & Computer Arithmetic

Question 9, GATE 2017: Two 8-bit two’s-complement numbers A7...A0 and B7...B0 are added, producing S7...S0 and carry bits C7...C0. A0 and B0 are least significant. Which detects overflow? A C7=1; B all carries 1; C A7 B7 ¬S7 + ¬A7 ¬B7 S7=1; D A0 B0 ¬S0 + ¬A0 ¬B0 S0=1. Products mean AND and + means OR.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. In two’s complement the high bit is the sign. Opposite-sign addition cannot exceed both representable bounds, so overflow requires equal operand signs.

2. If both signs are 0, overflow means the result sign is 1: ¬A7∧¬B7∧S7. If both signs are 1, overflow means the result sign is 0: A7∧B7∧¬S7.

3. OR the two mutually exclusive cases to obtain C. For example, 127+1 produces negative 8-bit result without needing an unsigned carry-out; sign overflow and unsigned carry are different tests.

Original paper, page 5 · Answer key

1 mark · MCQ
Report issue

Overflow when adding opposite signs

Number Systems & Computer Arithmetic

Question 1.21, GATE 2002: Which statement about overflow in two’s-complement addition is correct?
(A) A carry from the sign-bit addition always flags overflow.
(B) Adding a positive value to a negative value cannot overflow.
(C) Overflow is flagged when the carries from the sign bit and the preceding bit agree.
(D) None of these.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Contrast carry with signed overflow.

Step 2: In four bits, 0111+0001=1000 overflows the signed range even though there is no final carry. Conversely, 1111+0001=0000 with a carry represents−1+1=0 without signed overflow. These examples rule out a carry-only test. Opposite-sign operands always have a sum between the two operands and therefore within range.

Conclusion: If a≥0 and b<0 are representable, their sum lies between b and a and remains representable. Thus opposite-sign addition cannot overflow, B. For two’s complement, overflow is the XOR of the carry into and out of the sign position, not simply the outgoing carry or equality of those carries.

Original paper, page 3

Descriptive
Report issue

Signed addition overflow

Number Systems & Computer Arithmetic

Question 4(a), GATE 1992: Explain when addition in fixed-width two’s-complement arithmetic overflows, and why carry out of the most significant bit is not sufficient.
Tap to enlarge
Answer & solution

Answer: Overflow iff equal-sign operands produce the opposite-sign result; V = carry into sign bit XOR carry out. (no official key was published)

For a w-bit two’s-complement word the representable interval is −2w−1 through 2w−1−1. Hardware retains the low w bits of the mathematical sum. Overflow means the mathematical signed sum lies outside this interval, not merely that an unsigned carry was discarded.

Let a,b be the operand sign bits and s the retained result sign bit. The overflow flag is V=(¬a∧¬b∧s)∨(a∧b∧¬s). Two nonnegative numbers overflow only by producing a sign bit of 1; two negative numbers overflow only by producing a sign bit of 0. Opposite-sign operands cannot overflow: their sum lies between the operands and hence within the representable interval.

Equivalently, if c_in is the carry into the sign-bit adder and c_out its outgoing carry, V=c_in XOR c_out. This follows by considering the sign-bit full-adder cases: for equal operand signs an incorrect result sign occurs precisely when these carries differ; for unequal signs they agree.

For four bits, 0111+0001=1000 represents 7+1 as −8: overflow occurs despite no outgoing carry. Conversely 1111+0001=0000 with carry 1 represents −1+1=0 correctly: carry occurs without overflow. Finally 1000+1111=0111 with carry 1 is −8+(−1), which really does overflow. These examples separate the unsigned carry flag from the signed overflow flag.

Original paper, page 5