Digital Logic · Error Detection and Correction
Hamming Code: Single-Bit Error Correction and Number of Parity Bits
Overview
Hamming code is a single-bit error correction code: it can detect and correct an error in one bit of a transmitted word.
It works by adding redundant parity bits to the message bits, with the number of parity bits chosen so that every possible single-bit error position and the no-error case can be distinguished.
Key concepts
- Hamming code: a single-bit error correction code that detects and corrects an error in one bit of the transmitted word.
- Why only single-bit: a one-bit error is the most frequently occurring error, and the probability that more than one bit gets corrupted is very low.
The design assumption is therefore at most one bit error (two bits will not get corrupted). - Message bits (): the actual data to be transmitted.
- Parity bits (): bits added to the message bits. They are redundant — they carry no message information and are useful only for error correction.
- Transmitted word: the total bits sent, equal to .
- Role of each parity bit: each of the parity bits is assigned responsibility for some selected message bits. If anything goes wrong in those selected bits, that parity bit indicates "one of these has got corrupted."
How it works
- Let the actual data to be transmitted have bits.
- Add parity bits to these bits; the bits are redundant and used only for error correction.
- The total transmitted word is bits.
- At the receiver, the cases to distinguish are:
- No error at all → 1 case.
- Exactly one bit corrupted → any one of the bit positions may be the corrupted one → cases.
- Total cases = .
- Each case must be identified separately. The parity bits give distinct combinations, so these must be at least as many as the number of cases: .
- Choose the smallest satisfying this, because sending more redundant parity bits than necessary is undesirable.
- Each parity bit is given charge of a subset of message bits; a mismatch flags corruption among its assigned bits.
Formulas
-
- = number of message (data) bits
- = number of parity (redundant) bits
- = total transmitted bits
- = total cases to handle (all single-bit error positions plus the no-error case)
- = number of combinations available from parity bits
- Total transmitted length
Worked examples
Find for message bits.
- Total bits transmitted .
- Cases to handle single-bit-error cases no-error case .
- Condition: .
- Test smallest values of :
| Satisfied? | |||
|---|---|---|---|
| 1 | 2 | 6 | No |
| 2 | 4 | 7 | No |
| 3 | 8 | 8 | Yes |
- So parity bits are needed for 4 message bits.
- Total transmitted word bits.
- With 7 bits, the cases are: error in bit 1, bit 2, bit 3, bit 4, bit 5, bit 6, bit 7, or no error → 8 cases.
- Since 3 parity bits give combinations, each combination represents exactly one case, so all 8 cases are handled.
Revision summary
- Hamming code performs single-bit error correction; the assumption is at most one bit error.
- Parity bits are redundant and exist only for error correction.
- Find the number of parity bits from , choosing the smallest .
- For : , total word length 7 bits, handling 8 cases (7 error positions + no error).
- Each parity bit is given charge of a subset of message bits; a mismatch flags corruption among its assigned bits.
- Shortcut: For , check in order against ; the first that satisfies it (here 3) is the answer.
Previous-year exam insights
- In Hamming code, parity bits are placed at positions that are powers of 2 (1, 2, 4, 8, ...) in the transmitted word, counting positions from 1; all other positions hold message bits.
Asked inUGC NET 2015 - The syndrome (the set of check-bit mismatches read as a binary number, with the parity bit at position giving bit k) directly gives the position of the erroneous bit; a syndrome of all zeros means no error.
Asked inUGC NET 2015 - To correct a single-bit error, flip the bit at the position indicated by the syndrome; the corrected word then yields the original data bits from the non-power-of-2 positions.
Asked inUGC NET 2015 - Each parity bit at position is computed over all bit positions whose binary index has the k-th bit set (including the parity bit itself), using even parity by convention.
Asked inUGC NET 2015 - Hamming code with minimum Hamming distance 3 can correct any single-bit error, or alternatively detect (but not correct) any double-bit error, but not both at once (a double error would be miscorrected as a single error); with an extra overall parity bit (extended Hamming, distance 4) it can correct single errors and detect double errors (SECDED).
- The number of parity bits needed grows logarithmically: for M data bits the smallest P with gives total word length M + P, e.g. M=8 needs P=4 (12 bits), M=16 needs P=5 (21 bits).