> hamming | (7,4) | ecc <
// Hamming Code - Error correction code for reliable data transmission
Error Correction
Automatically detects and corrects single-bit errors in data.
Double Error Detection
Can detect (but not correct) two-bit errors in each block.
Minimal Overhead
Only 3 parity bits for every 4 data bits (75% efficiency).
>> technical info
How Hamming Code Works:
Hamming(7,4) code adds 3 parity bits to every 4 data bits, creating 7-bit blocks. Parity bits are placed at positions that are powers of 2 (1, 2, 4). When errors occur, the syndrome (parity check result) points directly to the error position.
Hamming(7,4) Structure:
Data: 1011 (4 bits) Positions: P1 P2 D1 P3 D2 D3 D4 Hamming: 1 0 1 1 0 1 1 P1 = D1 ⊕ D2 ⊕ D4 = 1 ⊕ 0 ⊕ 1 = 0 P2 = D1 ⊕ D3 ⊕ D4 = 1 ⊕ 1 ⊕ 1 = 1 P3 = D2 ⊕ D3 ⊕ D4 = 0 ⊕ 1 ⊕ 1 = 0
Why Use Hamming Code:
- >Memory error correction
- >Satellite communication
- >Data storage systems
- >Network transmission
- >RAID arrays
>> frequently asked questions
What is Hamming code?
Hamming code is an error correction code invented by Richard Hamming in 1950. It adds parity bits to data that allow automatic detection and correction of single-bit errors.
What does (7,4) mean?
Hamming(7,4) means 7 total bits with 4 data bits and 3 parity bits. It can correct any single-bit error in the 7-bit block. Other variants include (15,11) and (31,26).
How does error correction work?
When receiving data, parity bits are recalculated. If they don't match, the syndrome (difference) directly indicates which bit is wrong. The error is fixed by flipping that bit.
Hamming vs other ECC?
Hamming code is simple and efficient for single-bit errors. More complex codes like Reed-Solomon can correct multiple errors but have higher overhead. Hamming is perfect for low-noise channels.
汉明码(Hamming Code)怎么计算校验位?手算示例
汉明码 Hamming(7,4) 在 4 个数据位的基础上添加 3 个校验位,能 检测并纠正任意 1 位错误。
位置布局(位置 1 开始):P1 P2 D1 P3 D2 D3 D4
校验位 P1/P2/P3 放在位置 1、2、4(均为 2 的幂)。
校验位计算:
• P1 = D1 XOR D2 XOR D4(覆盖位置 1、3、5、7)
• P2 = D1 XOR D3 XOR D4(覆盖位置 2、3、6、7)
• P3 = D2 XOR D3 XOR D4(覆盖位置 4、5、6、7)
示例:数据 1011(D1=1, D2=0, D3=1, D4=1)
• P1 = 1⊕0⊕1 = 0
• P2 = 1⊕1⊕1 = 1
• P3 = 0⊕1⊕1 = 0
最终 7 位 Hamming 码:0 1 1 0 0 1 1(P1 P2 D1 P3 D2 D3 D4)。
纠错原理:接收端重算校验位,得到的“综合症”(syndrome)二进制值直接指向出错的位置(比如 syndrome=101=5,表示第 5 位翻转,取反即可恢复)。
ハミング符号(Hamming Code)— ECC メモリでの実用例
ハミング符号は 1950 年 Richard Hamming が発明した最も古典的な 誤り訂正符号(ECC)。現代で最も重要な応用は ECC メモリ(Error-Correcting Code memory)で、サーバー用 DDR4/DDR5 RDIMM では SEC-DED(Single Error Correction, Double Error Detection)方式が標準。
仕組み:
• 64 ビットのデータに 8 ビットの Hamming 拡張パリティを付加 → 72 ビット幅。
• シングルビットエラー(宇宙線、α粒子などによる)は自動修正。
• ダブルビットエラーは検出して OS に通知(mcelog で確認可能)。
• DDR5 は on-die ECC を内部に実装、さらに外部 ECC と組み合わせる。
ECC メモリなしのサーバーで大容量メモリ(64GB+)を 24h 稼働させると、数日〜数週間に 1 回は未訂正のビット反転が統計的に発生する。Hamming code が地球上のクラウドコンピューティングを支えていると言っても過言ではない。
Code Hamming — à quoi sert-il exactement ?
Le code de Hamming (ou correction d'erreur de Hamming) est une forme de FEC (Forward Error Correction) qui ajoute de la redondance aux données pour corriger les erreurs sans retransmission. Usages principaux :
• Mémoire ECC — les serveurs et stations de travail critiques détectent et corrigent les bit flips spontanés.
• Mémoire flash NAND — les SSD utilisent BCH (généralisation de Hamming) pour gérer l'usure des cellules.
• Communication satellite — les sondes Voyager utilisent Golay (cousin plus puissant) pour survivre au bruit cosmique.
• QR codes — emploient Reed-Solomon (pas Hamming), mais le principe est le même.
• Disques RAID 2 (historique) — distribuait les bits Hamming sur plusieurs disques.
Hamming(7,4) a 3/7 ≈ 43% de redondance. Les codes modernes (LDPC, Turbo) s'approchent de la limite de Shannon avec 10-20% seulement.
How does the syndrome pinpoint the error position?
This is the elegant part of Hamming codes. After receiving 7 bits, the decoder recomputes the three parity checks:
• S1 = P1 XOR bits at positions 3,5,7
• S2 = P2 XOR bits at positions 3,6,7
• S3 = P3 XOR bits at positions 5,6,7
If all three are 0, no error. Otherwise, interpret S3 S2 S1 as a 3-bit binary number — that number is the 1-indexed position of the corrupted bit.
This works because each data bit is covered by a unique combination of parity bits, and the parity positions are powers of 2. Richard Hamming chose this structure specifically so the syndrome would directly encode the error location in binary. Flip that bit → error corrected. No lookup table, no search — just XOR and index.
This design is why Hamming codes are still in silicon 70 years later: the circuitry is trivially small.
What about Hamming(15,11), Hamming(31,26), and extended variants?
Hamming(7,4) is the smallest practical code. The family generalizes to Hamming(2^r - 1, 2^r - 1 - r) for any integer r ≥ 2:
• Hamming(7,4): r=3, 4 data + 3 parity = 7 bits. Rate 4/7 ≈ 57%.
• Hamming(15,11): r=4, 11 data + 4 parity = 15 bits. Rate 11/15 ≈ 73%.
• Hamming(31,26): r=5, 26 data + 5 parity = 31 bits. Rate 26/31 ≈ 84%.
• Hamming(63,57): r=6, 57 data + 6 parity = 63 bits. Rate 57/63 ≈ 90%.
Larger codes have less overhead but correct only one bit per block — so if your channel has bursts, small blocks are safer. Extended Hamming (adding 1 more overall parity bit) upgrades SEC to SEC-DED — the version actually deployed in ECC RAM.