Introduction

Fixed-point representation places an implied binary point at a fixed position in a word: integer formats put it after the LSB, fractional formats before the MSB of the fraction field. Arithmetic uses the same adders as integer two's complement, with overflow and scaling rules. This note consolidates unsigned and two's-complement addition, subtraction, multiplication ranges, and overflow detection for GATE.

GATE asks which flags an addition sets, whether a signed or unsigned result overflowed, how many bits a sum or product needs, the range and resolution of a fixed-point format, and the effect of arithmetic shifts.

Prerequisites

Core concepts

Integer ranges

Encoding (n bits)MinMax
Unsigned02n−12^n-1
Two's complement−2n−1-2^{n-1}2n−1−12^{n-1}-1

Fractional fixed-point

A word with ii integer bits and ff fraction bits (i+f=ni+f=n, including sign if signed) represents multiples of 2−f2^{-f}. Scaling by 2f2^{f} converts to pure integer arithmetic: the pattern read as an integer kk stands for k⋅2−fk \cdot 2^{-f}.

  • Resolution (step): 2−f2^{-f}.
  • Signed range (two's complement, sign bit counted in ii): −2i−1-2^{i-1} to 2i−1−2−f2^{i-1} - 2^{-f}.
  • Unsigned range: 00 to 2i−2−f2^{i} - 2^{-f}.

This note writes Qii.ff with the sign bit counted in ii, so Q1.7 is an 8-bit signed fraction. Some texts write the same format as Q7 or Q0.7; check the stem's convention.

Converting a real number. Multiply by 2f2^f, round (or truncate) to an integer kk, then encode kk in two's complement only if kk is representable in the format. With no overflow, truncation error is below 2−f2^{-f}, and round-to-nearest error is at most 2−f−12^{-f-1}. Reject an out-of-range value here; a separate saturation or wrap policy would not retain these quantization-only bounds.

Overflow and wrap

  • Unsigned add: overflow iff final carry-out is 1 (for sum that should fit in nn bits).
  • Unsigned subtract A−BA - B: a borrow (the result is wrong) iff A<BA < B; with A+B‾+1A + \overline{B} + 1 hardware that is carry-out 0.
  • Two's complement add: overflow iff cn⊕cn−1=1c_n\oplus c_{n-1}=1, equivalently same-sign operands with opposite-sign result.
  • Two's complement subtract A−BA - B: overflow iff AA and BB have different signs and the result's sign differs from AA's.
  • Negation: −(−2n−1)-(-2^{n-1}) overflows; it returns −2n−1-2^{n-1} itself.
  • Wrap-around still produces a defined pattern mod 2n2^n; overflow means that pattern is not the mathematical sum.

Multiplication

  • An unsigned n×nn\times n product fits in 2n2n bits; that width is required in the worst case for n≥2n\ge2. For n=1n=1, the largest product is 1 and one bit suffices.
  • Two's complement n×nn\times n product also fits in 2n2n bits. In fact 2n−12n-1 bits hold every product except (−2n−1)×(−2n−1)=22n−2(-2^{n-1}) \times (-2^{n-1}) = 2^{2n-2}, which needs the full 2n2n.
  • For a signed product, truncating a product back to nn bits overflows when high bits are not a sign extension of the kept part. For unsigned arithmetic, overflow instead means some discarded high bit is nonzero.
  • In fixed point, Qi1i_1.f1f_1 times Qi2i_2.f2f_2 gives Q(i1+i2)(i_1 + i_2).(f1+f2)(f_1 + f_2): the fraction bits add.

Sums of many terms

For positive integers n,kn,k, n+⌈lg⁡k⌉n+\lceil\lg k\rceil bits are a sufficient guard-bit bound for adding kk unsigned nn-bit numbers. The exact minimum width is ⌈lg⁡(k(2n−1)+1)⌉\lceil\lg(k(2^n-1)+1)\rceil. Doubling the term count adds at most one required bit.

Two's-complement overflow cases for 4-bit addition
Figure 1. Four 4-bit additions: 5+35+3, 5+65+6, (−3)+(−6)(-3)+(-6), 5+(−3)5+(-3), with overflow flags and carry into/out of the sign bit marked.

How it works

Detecting signed overflow in hardware

Compute cnc_n and cn−1c_{n-1} from the adder; XOR them. Alternatively compare sign bits of operands and result:

V=an−1 bn−1 sn−1‾+an−1‾ bn−1‾ sn−1.V = a_{n-1}\,b_{n-1}\,\overline{s_{n-1}} + \overline{a_{n-1}}\,\overline{b_{n-1}}\,s_{n-1}.

Both forms give the same VV on every input pair.

Status flags together

After an nn-bit two's-complement add producing pattern ss:

  • Z is 1 iff s=0s=0.
  • N is the MSB of ss.
  • C is the unsigned carry-out of the MSB.
  • V is cn⊕cn−1c_n\oplus c_{n-1}.

Over all 4-bit additions, only 9 of the 16 combinations of (Z,N,C,V)(Z, N, C, V) occur. ZZ and NN are never both 1, and when V=1V = 1, NN is the complement of CC: a positive overflow has C=0C = 0 and N=1N = 1, a negative overflow C=1C = 1 and N=0N = 0. For 5+35+3 in 4 bits (0101+0011=10000101+0011=1000): Z=0Z=0, N=1N=1, C=0C=0, V=1V=1. For (−8)+(−8)(-8) + (-8): 00000000 with Z=1Z = 1, C=1C = 1, V=1V = 1.

Borrow polarity. After A+B‾+1A + \overline{B} + 1, carry-out 1 means no borrow. Processor families differ in whether the stored flag is this carry or its complement (the borrow); follow the definition the question gives.

Shifts

  • Arithmetic right shift by kk divides by 2k2^k and rounds toward −∞-\infty (floor): −5≫1=−3-5 \gg 1 = -3, not −2-2.
  • Left shift by 1 doubles the value and overflows (signed) when the two top bits differ before the shift.

Related material. Some DSP datapaths clamp to min/max on overflow instead of wrapping. Saturation circuits are a DSP extension not named separately in the official syllabus.

Algorithms and pseudocode

Patterns are nn-bit integers; mod is the non-negative remainder.

Text
ADD-DETECT(a, b, n, signed)
1  t <- a + b; s <- t mod 2^n; carry_out <- floor(t / 2^n)
2  if not signed then
3      ovf <- carry_out
4  else
5      ovf <- (sign(a)=sign(b)) and (sign(s)!=sign(a))
6  return (s, ovf)

SUB-DETECT(a, b, n, signed)
1  t <- a + (2^n - 1 - b) + 1; s <- t mod 2^n; carry_out <- floor(t / 2^n)
2  if not signed then ovf <- (carry_out = 0)        // borrow
3  else ovf <- (sign(a)!=sign(b)) and (sign(s)!=sign(a))
4  return (s, ovf)

TO-FIXED(x, f, n)                 // real x to signed Q format, round to nearest
1  k <- round(x * 2^f)
2  if k < -2^(n-1) or k > 2^(n-1) - 1 then report overflow
3  return k mod 2^n

MUL-WIDTH(n)
1  return 2*n          // bits to hold full product

Mathematical explanation

Identifying bit patterns with Z/2nZ\mathbb{Z}/2^n\mathbb{Z} makes wrap modularly correct always. The signed interpretation is only faithful when the mathematical result lies in [−2n−1,2n−1−1][-2^{n-1},2^{n-1}-1]. Multiplication of two representatives corresponds to modular multiplication; the full signed product needs the double-width two's encoding.

Why cn⊕cn−1c_n \oplus c_{n-1} detects overflow. If both operands are non-negative, cn=0c_n = 0, and the sign bit of the sum equals cn−1c_{n-1}; overflow (a negative-looking result) is exactly cn−1=1c_{n-1} = 1. If both are negative, cn=1c_n = 1, and overflow (a non-negative result) is exactly cn−1=0c_{n-1} = 0. With mixed signs the true sum lies between the operands, so it cannot overflow, and cn=cn−1c_n = c_{n-1}.

Product widths. For unsigned operands, (2n−1)2=22n−2n+1+1<22n(2^n - 1)^2 = 2^{2n} - 2^{n+1} + 1 < 2^{2n}. For signed operands, the largest magnitude is (−2n−1)2=22n−2(-2^{n-1})^2 = 2^{2n-2}, one more than the 2n−12n - 1-bit maximum 22n−2−12^{2n-2} - 1; every other product has magnitude at most 2n−1(2n−1−1)2^{n-1}(2^{n-1} - 1), within 2n−12n - 1 bits.

Worked examples

Example 1: unsigned 4-bit 9+89+8

1001+1000=00011001+1000=0001 with carry 1: overflow, wrapped 1.

Example 2: signed 4-bit 5+35+3

0101+0011=10000101+0011=1000 (−8-8): overflow (both positive, result negative). Carry into sign 1, carry out 0, XOR 1.

Example 3: signed 5+(−3)5+(-3)

0101+1101=00100101+1101=0010 (2): no overflow. Carry into sign 1 and carry out 1, so V=0V = 0; the unsigned carry C=1C = 1 is irrelevant here.

Example 4: the four cases of Figure 1

SumPatternsResultCarry into signCarry outVV
5+35 + 30101+00110101 + 00111000=−81000 = -8101
5+65 + 60101+01100101 + 01101011=−51011 = -5101
(−3)+(−6)(-3) + (-6)1101+10101101 + 10100111=70111 = 7011
5+(−3)5 + (-3)0101+11010101 + 11010010=20010 = 2110

Example 5: product width

(−8)×(−8)=64(-8)\times(-8)=64 in 4-bit two's (min −8-8): 64 needs at least 8-bit two's (0100000001000000). The next largest, (−8)×(−7)=56(-8) \times (-7) = 56, already fits in 7 bits (range −64-64 to 6363).

Example 6: Q1.3 format

Signed bit + 3 fraction bits; step 0.1250.125; range −1.0-1.0 to 0.8750.875. The value −0.375=−3/8-0.375 = -3/8 is the 4-bit two's-complement pattern of −3-3: 11011101.

Example 7: converting 0.30.3 to Q1.7

0.3×128=38.40.3 \times 128 = 38.4, which rounds to 38 = 0010011000100110. The stored value is 38/128=0.29687538/128 = 0.296875, an error of 0.0031250.003125, within the bound 2−8=0.003906252^{-8} = 0.00390625.

Example 8: signed subtraction overflow

In 4 bits, 3−(−5)=83 - (-5) = 8 overflows: 0011+0100+1=10000011 + 0100 + 1 = 1000, which reads as −8-8. The operands have different signs and the result's sign differs from the minuend's. By contrast (−3)−4=−7(-3) - 4 = -7 fits: 1101+1011+1=1 10011101 + 1011 + 1 = 1\,1001, result 1001=−71001 = -7.

Important properties and observations

  • Logical shift and arithmetic shift differ on signed data (see signed-number note).
  • Adding a positive to a negative never overflows in two's complement.
  • Subtracting two numbers of the same sign never overflows.
  • Flags in ALUs: Z (zero), N (sign), C (carry), V (overflow); definitions match the rules above.
  • Sign-extend the shorter operand before adding numbers of different widths.

Common misconceptions.

  • "Carry set means signed overflow." Only unsigned.
  • "n×nn\times n product fits in nn bits." Only with restrictions; generally needs 2n2n.
  • "Arithmetic right shift truncates toward zero." It floors: −5≫1=−3-5 \gg 1 = -3.
  • "Q-format names are universal." Whether the sign bit is counted varies; read the stem.

GATE examination perspective

  • WHICH FLAG. C vs V; when V=1V = 1, N≠CN \ne C.
  • RANGE. State min/max before computing; Qii.ff step 2−f2^{-f}.
  • DOUBLE WIDTH. Product size; 2n−12n - 1 bits except (−2n−1)2(-2^{n-1})^2.
  • SAME-SIGN RULE. Fast overflow mental check; for subtraction, different signs.
  • SHIFTS. Arithmetic right shift floors.

Summary

Sources

  1. M. Morris Mano, M. D. Ciletti, Digital Design, 5th ed., Pearson, 2013: Chapter 1, Sections 1.5 and 1.6, and Chapter 4, Section 4.5 (complements, signed numbers, adder-subtractor overflow context).

Next steps