der Mouse wrote:
So, you need
log2(width) bits [...].
But, you also have the "all bits are
correct" case which must be
conveyed. So, log2(width)+1 are required.
Yes, basic counting proofs make it clear that that many are necessary.
It is not obvious to me that they are sufficient - but then, I've never
really studied coding theory; it's quite possible there is a known way
of constructing a suitable code for any word size.
The beauty of the Hamming codes was the simplicity of doing so.
If you have D data bits, you take build an L-row matrix wherein
each column is the L-bit representation of such that no two columns
are the same -- and the "0...0" vector never appears (L is the
number of bits that you are adding to the data bits -- there must
be D+L columns in said matrix).
So, for an 8 bit value, you would create a matrix:
0 0 0 0 0 0 0 1 1 1 1 1
0 0 0 1 1 1 1 0 0 0 0 1
0 1 1 0 0 1 1 0 0 1 1 0
1 0 1 0 1 0 1 0 1 0 1 0
Your input code word (D+C digits... C=4 here) is then
multiplied by this matrix. A result of "0..0" indicates
a valid code word (no error). Any other value tells you
which bit needs to be twiddled in the input code word.
The "check digits" (given this form of the code) are
interspersed among the data digits by noting where the
column vectors in this matrix have only a single bit
set in them. (E.g. the 1st, 2nd, 4th and 8th columns).
You can obviously rearrange the columns. Or, select
a different subset of those available (e.g., replace the
last column with 1 1 1 1)
[let me know if this isn't quite right... I'm just calling
it up from memory and I haven't had to design any ECC
hardware in *decades*! :-/ ]