Andy Holt wrote:
There are several web sites that give the details on
how Hamming Codes (the
Note, not all ECC's are Hamming! It's beauty is that it is simple to
implement (though not as efficient as a code could theoretically be)
ECC normally used for memory) work. However, to
correct some misinformation
Except *disk* memory, of course... :>
above:
7 check bits are only sufficient for 57 data bits - you need 8 for 64 (or
anything up to
Sorry if my comment wasn't clear enough:
For 64 bit memory (assuming you want to treat it as a 64 bit
entity) you need 7 bits (minimum) to "correct a single bit error".
-----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^
Simple rule of thumb: the extra bits in some way need to be
able to tell you WHICH of the other bits is wrong. So, you need
log2(width) bits to specify one of "width" bits (e.g., 5 for
32 bits, 6 for 64 bits, 3 for 8 bits, etc.).
But, you also have the "all bits are correct" case which must
be conveyed. So, log2(width)+1 are required.
If you want to *detect* two bit errors, then you need extra
check digits.
(Hamming distance is the number of bits of "difference"
between VALID code words).
In particular, you can DETECT no more than X errors if the
Hamming distance is X+1. Note that n simple parity, all
valid code words differ in at least 2 bits -- a data bit
and, if a data bit is toggled (to represent a different
value from some *other* data value), that means the parity bit
is also toggled! So, parity can detect 2=X+1 or *1* error.
You can CORRECT no more than Y errors if the Hamming distance
is 2Y+1. Since the distance for simple parity (above)
is 2, 2=2Y+1 or *0* bits can be corrected.
So, to DETECT 2 errors, you need a Hamming distance of 3.
To CORRECT 1 error you also need a Hamming distance of 3.
But, there's no free lunch. You get one or the other
"capability" for that distance. To do *both*, you need a
Hamming distance of X+Y+1 -- or, 4, in this case.
A Hamming CODE will correct a single bit error (distance = 3).
A Hamming code is formed by adding C bits to the data word.
It must be possible to indicate which of the resulting D+C bits
is in error -- so, log2(D+C) <= C (this is roughly C=log2(D)+1).
But, this just gives you a "distance 3" code. To get a distance
*4* code (which allows CORRECT 1 *and* DETECT 2), you add a
parity bit to the C bits (one extra bit means the distance is
now 1 greater between VALID code words).
When the input code word differs by more bits than can be
accommodated, the code typically "corrects" to a wrong
data value (or, ignores the error altogether!) -- just
like simple parity...
120). This is to detect all 1- or 2- bit errors and to
correct all 1-bit
errors (including those in the check bits themselves). With minor
reshuffling of the codes, if necessary, it is also possible to ensure that
the two commonest multi-bit failures (all 0s, all 1s) are considered to be
2-bit errors and thus no attempt to "correct" would happen.