Hamming Code Calculator | Error Detection & Single-Bit Correction
Encode binary data words with Hamming error-correcting codes. Supports Hamming(7,4) and Hamming(15,11). Shows parity bit placement, codeword construction, and syndrome decoding. Simulate a single-bit error by flipping any bit position and watch the calculator locate and correct the error automatically.
| Position | Type | Covers Positions | Bits |
|---|---|---|---|
| 1 | parity | 1,3,5,7 | p₁, d₁, d₂, d₄ |
| 2 | parity | 2,3,6,7 | p₂, d₁, d₃, d₄ |
| 3 | data | — | d₁ |
| 4 | parity | 4,5,6,7 | p₄, d₂, d₃, d₄ |
| 5 | data | — | d₂ |
| 6 | data | — | d₃ |
| 7 | data | — | d₄ |
What Is the Hamming Code Calculator | Error Detection & Single-Bit Correction?
Hamming codes are the simplest class of single-error-correcting (SEC) linear block codes. Each parity bit is responsible for a subset of positions whose indices share a specific bit in their binary representation. On decoding, recomputing the parity bits produces a syndrome that directly points to the error position — or zero if no error occurred.
Formula
Hamming(7,4): place 4 data bits at positions 3,5,6,7. Parity bits at 1,2,4: p₁=d₁⊕d₂⊕d₄, p₂=d₁⊕d₃⊕d₄, p₄=d₂⊕d₃⊕d₄. Syndrome on receive: s₁s₂s₄ (binary) = error position. If 0, no error.
How to Use
- 1
Select Encode to convert data bits to a codeword, or Decode to correct a received (possibly corrupted) codeword.
- 2
Select the code type: Hamming(7,4) uses 4 data bits and produces a 7-bit codeword; Hamming(15,11) uses 11 data bits and produces a 15-bit codeword.
- 3
For Encode: enter exactly 4 (or 11) binary digits (0s and 1s only).
- 4
For Decode: enter the full received codeword — 7 bits for (7,4) or 15 bits for (15,11).
- 5
Click Encode or Decode & Correct to run the algorithm.
- 6
In Encode mode, use the "Flip bit N" buttons to simulate a single-bit transmission error, then watch the decoder identify and correct it.
- 7
Load a preset to see a pre-built worked example instantly.
Choose Encode or Decode mode, select the code type (7,4 or 15,11), enter the required binary digits, then click Encode or Decode & Correct.
Example Calculation
Encode 1011 with Hamming(7,4): d₁=1, d₂=0, d₃=1, d₄=1. p₁=1⊕0⊕1=0, p₂=1⊕1⊕1=1, p₄=0⊕1⊕1=0. Codeword = [0,1,1,0,0,1,1]. If bit 3 is flipped to get [0,1,0,0,0,1,1], syndrome = 011 = 3 → correct position 3.
Understanding Hamming Code | Error Detection & Single-Bit Correction
Hamming(7,4) Parity Bit Coverage
| Parity Bit | Position | Covers Positions | Binary Pattern | XOR Formula |
|---|---|---|---|---|
| p₁ | 1 | 1, 3, 5, 7 | Bit 0 set | p₁ = d₁ ⊕ d₂ ⊕ d₄ |
| p₂ | 2 | 2, 3, 6, 7 | Bit 1 set | p₂ = d₁ ⊕ d₃ ⊕ d₄ |
| p₄ | 4 | 4, 5, 6, 7 | Bit 2 set | p₄ = d₂ ⊕ d₃ ⊕ d₄ |
Syndrome bits s₁, s₂, s₄ are recomputed on reception. Error position = s₁·1 + s₂·2 + s₄·4. If non-zero, that bit is flipped to correct it.
Hamming Code Efficiency Comparison
| Code | Data bits (k) | Total bits (n) | Parity bits (r) | Efficiency k/n | Errors correctable |
|---|---|---|---|---|---|
| Hamming(3,1) | 1 | 3 | 2 | 33.3% | 1-bit |
| Hamming(7,4) | 4 | 7 | 3 | 57.1% | 1-bit |
| Hamming(15,11) | 11 | 15 | 4 | 73.3% | 1-bit |
| Hamming(31,26) | 26 | 31 | 5 | 83.9% | 1-bit |
| Hamming(63,57) | 57 | 63 | 6 | 90.5% | 1-bit |
| SECDED(8,4) | 4 | 8 | 4 | 50.0% | 1-bit correct + 2-bit detect |
Real-World Applications
- ▸RAM ECC (Error Correcting Code): most server-class DDR4/DDR5 memory uses Hamming-based SECDED to silently correct single-bit errors caused by cosmic rays or electrical noise.
- ▸Satellite and deep-space communications: NASA Voyager used Hamming-derived codes; modern spacecraft use stronger codes like Reed-Solomon and turbo codes.
- ▸Hard drives and SSDs: block-level ECC in NAND flash uses BCH codes (a generalization of Hamming) to correct multiple bit errors per page.
- ▸QR codes: Reed-Solomon error correction (related theory) lets QR codes recover from up to 30% damage.
- ▸Network data link layer: some protocols use Hamming distance concepts to detect multi-bit burst errors in frames.
- ▸Medical imaging: MRI and CT scanners use ECC in their data buses to prevent silent corruption in life-critical imaging data.
- ▸Compact Discs (CD): Cross-Interleaved Reed-Solomon Coding (CIRC) corrects scratches using algebraic codes sharing Hamming code foundations.
Frequently Asked Questions
Why are parity bits placed at power-of-2 positions?
Each power-of-2 position has a unique binary representation with exactly one bit set. By assigning a parity bit to each power of 2, every non-parity position has a unique combination of parity bits covering it. This means the syndrome directly encodes the error position as a binary number — an elegant mathematical design by Richard Hamming in 1950.
What is SECDED and how is it different from basic Hamming?
SECDED (Single Error Correct, Double Error Detect) adds one overall parity bit to a Hamming code. This extra bit detects whether one or two bit errors occurred: if the overall parity is wrong and the syndrome is non-zero, it is a correctable single-bit error; if the overall parity is correct but the syndrome is non-zero, two bits were flipped and the error is detected but not correctable. Modern ECC RAM uses SECDED.
What is the Hamming distance?
The Hamming distance between two codewords is the number of positions where they differ. A Hamming(7,4) code has minimum Hamming distance 3, which guarantees detection of all 2-bit errors and correction of all 1-bit errors. The general rule: to detect d errors you need minimum distance d+1; to correct t errors you need minimum distance 2t+1.
Can Hamming codes handle burst errors?
Standard Hamming codes handle only single-bit errors. For burst errors (multiple consecutive bit flips common in storage and communications), interleaved Hamming codes or stronger codes like Reed-Solomon are used. Interleaving spreads burst errors across multiple codewords so each codeword sees at most one error.
What happens if two bits are flipped?
A standard Hamming code will compute a non-zero syndrome pointing to a wrong position and "correct" the wrong bit, making things worse. SECDED detects this case using the overall parity bit, flagging it as uncorrectable. This is why modern ECC RAM detects (and logs) double-bit errors even though it cannot fix them.
You Might Also Like
Explore 360+ Free Calculators
From math and science to finance and everyday life — all free, no account needed.