Storage, Buses & I/O

an error-correcting code

/ E-C-C /

Bits are physical: a cosmic ray, a wisp of electrical noise, or an aging memory cell can flip a 0 into a 1. If you store or send raw bits, you have no way to know a flip happened. The fix is to add carefully chosen extra bits so the data carries its own self-check. An error-correcting code adds redundant bits to a message such that an error not only stands out but can be located and repaired automatically — like a sentence written so cleverly that a single typo is obvious and the intended word is recoverable.

Start with the simplest idea: parity. Add one extra bit set so the total number of 1s is even. Now if any single bit flips, the count becomes odd and you know something is wrong — but you cannot tell which bit, so you can detect one error but not correct it. The leap to correction is the Hamming idea: use several parity bits, each guarding an overlapping subset of the data bits, arranged so that each possible single-bit error trips a unique pattern of failing parity checks. That pattern is the binary address of the broken bit, so you simply flip it back. A single-error-correcting Hamming code over k data bits needs about log2(k) check bits; real memory ECC typically uses a SECDED code — single-error correct, double-error detect.

Why it matters: ECC is dependability woven into the data itself, and it is everywhere — server memory (ECC DRAM), disks and SSDs (which store strong codes per sector), CDs, network packets, deep-space links. The honest limits: a code is sized for a certain number of errors. A single-correct code silently mis-repairs if two bits flip; every code has a threshold beyond which it fails or even 'corrects' to the wrong value. More protection costs more redundant bits and computation. ECC does not make errors impossible — it makes the common, small errors invisible and the rarer big ones at least detectable.

Parity on the byte 0b0110010 (three 1s, odd): append a parity bit of 1 to make four 1s, even. If the byte arrives as 0b0010010 (two 1s, even — but the parity bit says it should be odd... actually now even total fails), the mismatch flags an error. A Hamming code with extra check bits would go further and name which bit flipped, so the receiver flips it back to the original.

Parity detects one flip; the Hamming idea adds enough check bits to also pinpoint and repair it.

Every code has a limit. A single-error-correcting code that meets two flips at once may 'correct' to the wrong value with full confidence. ECC reduces the chance of undetected corruption; it cannot eliminate it.

Also called
ECCerror correction codeHamming codeparity錯誤更正碼ECC