Skip to content
GATEiit

GATE EC · Communications

Fundamentals of error correction, Hamming codes, CRC

Hamming distance and what a code can detect or correct, linear block codes with generator and parity-check matrices, Hamming codes with syndrome decoding, and CRC encoding by modulo-2 polynomial division.

Before you start

  • XOR and modulo-2 arithmetic →

    Parity, syndromes and CRC division are all XOR operations; addition and subtraction are the same in modulo 2.

  • Matrix multiplication →

    Linear block codes encode as c=mG and check with s=rHT.

  • Polynomial long division

    CRC treats a bit string as a polynomial and divides it by the generator.

Concept notes

1. Hamming distance and error capability

The Hamming weight w(c) of a codeword is its number of 1s. The Hamming distance d(u,v) is the number of positions where u and v differ, which equals w(u⊕v).

The minimum distance dmin of a code is the smallest distance between any two distinct codewords. It decides everything:

Goal Condition
Detect up to s errors dmin≥s+1
Correct up to t errors dmin≥2t+1
Correct t and detect s (s≥t) together dmin≥t+s+1

So t=⌊dmin−12⌋ errors can be corrected and dmin−1 detected.

Intuition: correction picks the nearest codeword. If spheres of radius t around codewords do not overlap, every pattern of t or fewer errors still lies closest to the transmitted codeword.

Single parity bit (even parity): dmin=2. It detects any odd number of errors and corrects none.

For a linear code, dmin equals the smallest weight of a non-zero codeword, so you need not compare all pairs.

2. Linear block codes

An (n,k) block code maps k message bits to an n-bit codeword by adding n−k parity bits. There are 2k codewords; the code rate is r=k/n.

The code is linear if the XOR of any two codewords is a codeword. The all-zero word is always a codeword.

Systematic form. With generator matrix G=[ Ik∣P ] (k×n), the codeword is c=mG: the message followed by the parity bits. The parity-check matrix is H=[ PT∣In−k ] ((n−k)×n), and every codeword satisfies cHT=0.

Syndrome decoding. For a received word r=c⊕e:

s=rHT=eHT

The syndrome depends only on the error pattern. s=0 means no detectable error. For a single error in position i, s equals the i-th column of H.

There are 2n−k syndromes, so a code can correct at most 2n−k−1 distinct non-zero error patterns. This gives the Hamming bound for a t-error-correcting code:

2n−k≥∑i=0t(ni)

A code that meets it with equality is perfect; Hamming codes are perfect for t=1.

3. Hamming codes

A Hamming code with m parity bits has

n=2m−1,k=2m−1−m,dmin=3

so it corrects any single error (or detects up to two, if used only for detection). Examples: (7,4), (15,11), (31,26).

To protect k data bits with single-error correction, the number of parity bits m must satisfy

2m≥k+m+1

(every one of the n single-error positions, plus "no error", needs its own syndrome).

Position scheme (7, 4). Number the bits 1 to 7. Parity bits sit at the powers of two: positions 1, 2, 4. Data bits sit at 3, 5, 6, 7. With even parity:

  • p1 checks positions 1, 3, 5, 7 (binary index has bit 0 set).
  • p2 checks positions 2, 3, 6, 7 (bit 1 set).
  • p4 checks positions 4, 5, 6, 7 (bit 2 set).

At the receiver, recompute the three checks c4c2c1. Read as a binary number, the syndrome is the position of the error; 000 means no error.

Extended Hamming code: add one overall parity bit, giving (8,4) with dmin=4. It corrects single errors and detects double errors at the same time (SEC-DED), used in computer memories.

check p1check p2check p41: p12: p24: p43: d15: d26: d37: d4
Hamming (7,4) with even parity: each circle is one parity check. Positions 3, 5, 6, 7 carry data; 1, 2, 4 carry parity

4. Cyclic redundancy check (CRC)

A CRC is an error-detecting code. Bits are read as polynomial coefficients: 1101↔x3+x2+1. Sender and receiver agree on a generator polynomial G(x) of degree r (r+1 bits).

Encoding:

  1. Append r zeros to the message: M(x) xr.
  2. Divide by G(x) using modulo-2 long division (XOR, no carries).
  3. The r-bit remainder R(x) is the CRC. Send M(x)xr+R(x), i.e. the message followed by the remainder.

The transmitted word is exactly divisible by G(x). The receiver divides what it gets by G(x): a non-zero remainder means an error.

What a CRC detects (with a degree-r generator whose xr and x0 terms are both present):

Error type Detected?
All single-bit errors Yes
All burst errors of length ≤r Yes
All odd numbers of bit errors Yes, if (x+1) is a factor of G(x)
All double errors Yes, for suitable G(x) and frame length
Errors that are a multiple of G(x) No (undetected)

CRC only detects; correction is done by retransmission (ARQ). Hamming codes and other block codes are used when the receiver must correct errors itself (FEC).

Formulas to remember

Hamming distance
d(u,v)=w(u⊕v)
Errors detectable
s=dmin−1
Errors correctable
t=⌊dmin−12⌋
Code rate
r=kn
Encoding and check
c=mG,cHT=0,s=rHT=eHT
Hamming code parameters
n=2m−1,k=n−m,dmin=3
Parity bits for single-error correction
2m≥k+m+1
Hamming bound
2n−k≥∑i=0t(ni)
CRC transmitted word
T(x)=M(x) xr+(M(x) xr mod G(x))

Common mistakes

  • Using t = d_min − 1 for correction; that is the detection limit. Correction is ⌊(d_min − 1)/2⌋.
  • Forgetting to append r zeros (r = degree of G, one less than the number of generator bits) before the CRC division.
  • Doing ordinary subtraction with borrows in CRC division; modulo-2 division uses XOR only.
  • Reading the Hamming syndrome in the wrong bit order; with checks c4 c2 c1, the number c4c2c1 in binary is the error position.
  • Checking 2^m ≥ k + m instead of 2^m ≥ k + m + 1; the extra 1 is the no-error syndrome.
  • Finding d_min of a non-linear code from the minimum weight; that shortcut holds only for linear codes.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Encoding 1011 with Hamming (7,4)

numerical

Encode the data bits d1d2d3d4=1011 with the (7,4) Hamming code, using even parity and the position scheme (parity at 1, 2, 4; data at 3, 5, 6, 7).

  1. Step 1: Place the data bits.

    Try it on paper first.

Example 2: Correcting a single error with the syndrome

numerical

The (7,4) codeword 0110011 is received as 0110111. Find the syndrome, the error position and the corrected data bits.

  1. Step 1: Recompute check 1 over positions 1, 3, 5, 7.

    Try it on paper first.

Example 3: CRC by modulo-2 division

numerical

Find the CRC and the transmitted frame for message 110101 with generator G(x)=x3+x+1.

  1. Step 1: Write the generator bits and append zeros.

    Try it on paper first.

Example 4: Minimum distance of a small linear code

conceptual

A linear code has codewords 00000, 01011, 10101, 11110. Find dmin and how many errors it can detect and correct.

  1. Step 1: Use the linear-code shortcut.

    Try it on paper first.

Previous year questions

3 official GATE EC questions on this topic, newest first.

Topic test

10 questions: up to 3 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE EC syllabus; being checked by a reviewer. Updated 2026-11-28. Spotted a mistake? Use Report an issue on any question, or contact us.