Hamming Code Calculator
Encode and decode Hamming codes, calculate parity bits and syndrome values, detect a single-bit error, automatically correct the erroneous bit and recover the original binary data.
| Parity Bit | Position | Checked Positions | Ones Count | Parity Value |
|---|---|---|---|---|
| Enter data and calculate to view parity analysis. | ||||
What Is Hamming Code?
Hamming code is a family of error-control codes that adds strategically positioned parity bits to binary data. The additional parity information allows a receiver to identify the position of a single erroneous bit and correct it.
Parity bits are placed at positions that are powers of two: 1, 2, 4, 8, 16 and so on. All remaining positions contain the original data bits.
What This Hamming Code Calculator Does
Hamming Code Encoder
Enter original data bits and the calculator automatically determines how many parity bits are required and generates the complete Hamming codeword.
Hamming Code Decoder
Enter a received Hamming codeword to recover the original data bits after parity analysis.
Error Detector
The calculated syndrome identifies whether a single-bit error exists and indicates its position.
Error Corrector
When a valid single-bit error position is detected, the calculator flips that bit and returns the corrected Hamming codeword.
How Many Hamming Parity Bits Are Required?
For m data bits and r parity bits, the number of parity bits must satisfy:
| Data Bits | Minimum Parity Bits | Total Hamming Bits |
|---|---|---|
| 1 | 2 | 3 |
| 2 | 3 | 5 |
| 3 | 3 | 6 |
| 4 | 3 | 7 |
| 5 to 11 | 4 | 9 to 15 |
| 12 to 26 | 5 | 17 to 31 |
Hamming Parity Bit Positions
Parity bits occupy positions that are powers of two. Data bits fill all other positions.
Type: P1 P2 D1 P4 D2 D3 D4
This arrangement allows each bit position to be uniquely represented by the combination of parity checks that include it.
Hamming Code Encoding Example
For four data bits, three parity bits are required because:
r = 3
2^3 = 8
m + r + 1 = 8
Therefore:
7-bit Hamming codeword
The calculator places the data into non-power-of-two positions and calculates parity bits according to the selected even or odd parity rule.
What Is a Hamming Syndrome?
The syndrome is produced by recalculating the parity checks of a received Hamming codeword. Each failed parity check contributes its parity position to the syndrome.
No single-bit error detected
Syndrome = 5
Error detected at bit position 5
The syndrome therefore acts as the binary address of the erroneous bit in a standard single-error-correcting Hamming code.
How Hamming Code Detects an Error
Each parity bit checks a different group of positions. If a transmitted bit changes, some parity groups fail while others remain valid.
Combining the failed parity positions produces the syndrome, which identifies the bit that should be corrected.
How Hamming Code Corrects a Single-Bit Error
1010101
Suppose syndrome:
5
Detected error:
Position 5
Correction:
Flip bit 5
0 becomes 1
or
1 becomes 0
After correction, data bits can be extracted from every non-parity position.
Even vs Odd Hamming Parity
| Parity Type | Rule | Goal |
|---|---|---|
| Even Parity | Choose parity bit so checked group has an even number of ones | Total ones count becomes even |
| Odd Parity | Choose parity bit so checked group has an odd number of ones | Total ones count becomes odd |
Encoder and decoder must use the same parity convention or the syndrome result will not be meaningful.
Standard Hamming Code vs SECDED
This calculator implements the standard Hamming single-error-correcting structure. Standard Hamming code can locate and correct one erroneous bit under the single-error assumption.
SECDED systems add an additional overall parity bit so they can provide Single Error Correction and Double Error Detection. That extended overall parity bit is not automatically added by this calculator.
Hamming Code Applications
Computer Memory
Error-correcting memory systems use related error-control techniques to detect and correct corrupted bits.
Digital Communications
Hamming codes demonstrate how redundant bits can improve reliability when data travels through noisy channels.
Computer Architecture
The syndrome concept is useful for learning hardware error-detection and correction logic.
Coding Theory
Hamming codes are a fundamental introduction to linear block codes, code distance and syndrome decoding.
Important Hamming Code Notes
Parity bit positions are numbered from the rightmost bit as position 1. This is important when reading the reported error position.
A syndrome of zero means all Hamming parity checks passed.
A nonzero syndrome identifies the position to flip under the assumption that no more than one bit is incorrect.
Standard Hamming code alone should not be assumed to reliably distinguish every possible multi-bit error pattern.
For guaranteed single-error correction plus double-error detection, an extended Hamming SECDED scheme with an additional overall parity bit is required.