# Hamming Code
## What is Hamming Code
Hamming code is an error correction technique invented by Richard Hamming in 1950 while working at Bell Labs. Unlike error detection techniques that only identify that an error has occurred, Hamming code can detect and correct single-bit errors in transmitted data without requiring retransmission. It can also detect, though not correct, double-bit errors. Hamming code achieves this by adding redundant parity bits at specific positions in the data, and the combination of these parity bits uniquely identifies the position of any single-bit error.
## How Hamming Code Works
In Hamming code, parity bits are inserted at positions that are powers of 2: positions 1, 2, 4, 8, 16, and so on. Data bits fill the remaining positions. Each parity bit covers specific data bit positions determined by the binary representation of the position number. Parity bit at position 1 covers positions 1, 3, 5, 7, 9, 11, and so on, which are positions whose binary representation has a 1 in the rightmost bit. Parity bit at position 2 covers positions 2, 3, 6, 7, 10, 11, and so on, which have a 1 in the second bit. Each parity bit is set to make the parity of all the bits it covers, including itself, even for even parity.
## Error Detection and Correction
When the receiver receives a Hamming-encoded message, it recalculates all the parity values. If all parity checks pass, no error occurred. If some parity checks fail, the positions of the failing parity bits are added together. This sum gives the position of the erroneous bit. The receiver then flips that bit to correct the error. For example, if parity checks at positions 1 and 4 fail, the error is at position 1 plus 4 equals 5. The receiver inverts bit 5.
## Example
For data bits 1011, the Hamming code positions are as follows. Positions 1, 2, and 4 are parity bits. Position 1, 2, 4, and 5 get values based on parity calculation. The process produces the complete codeword including parity bits that is transmitted. If bit 5 is flipped during transmission, the parity checks at positions 1 and 4 fail, and their sum 1 plus 4 equals 5 correctly identifies the error position.
## Applications
Hamming code is used in memory systems including ECC RAM, which stands for Error-Correcting Code RAM, to detect and correct single-bit memory errors. It is used in some storage systems. Modified forms of Hamming code are used in more sophisticated forward error correction schemes used in satellite communication and digital television broadcasting.Back to Subject