Hamming codes use parity principal to correct one error or detect two errors, but they are not capable of doing both simultaneously. One can use Hamming codes as an error detector to catch both single or double bit errors, or use them as an error corrector to modify single bit error. This is accomplished by using more than one parity bit, each computed on different combination of bits in the data.
The number of parity or error check bits required is given by the Hamming rule, and is a function of the number of bits of information transmitted. The Hamming rule is expressed by the following inequality.
Where d is the number of data bits and p is the number of parity bits. The result of appending the computed parity bits to the data bits is called the Hamming code word. The size of the code word c is obviously d+p, and a Hamming code word is described by the ordered set (c,d).
Codes with values of p < = 2 are hardly worthwhile because of the overhead involved. Therefore I will use a case when p = 3 and develop a (7, 4) code using even parity. 7 is the total bits of the code word, while 4 is the data bits in the code word. In real application larger code word are usually used.
A Hamming code word is generated by multiplying the data bits by a generator matrix G using “modulo-2 arithmetic.” This multiplication's result is called the code word vector (c1, c2. c3, ..... cn), consisting of the original data bits and the calculated parity bits.
The generator matrix G used in constructing Hamming codes consists of I (the identity matrix) and a parity generation matrix A:
An example of Hamming Code generator matrix:
The multiplication of a 4-bit vector (d1, d2, d3, d4) by G results in a 7-bit code word vector of the form (d1, d2, d3, d4, p1, p2, p3). It is clear that the A partition of G is responsible for the generation of the actual parity bits. Each column in A represents one parity calculation computed on a subset of d. The Hamming rule requires that p = 3 for a (7,4) code, therefore A must contain three columns to produce three parity bits.
If the columns of A are selected so each column is unique, it follows that (p1, p2, p3) represents parity calculations of three distinct subset of d. As shown in the figure below, validating the received code word r, involves multiplying it by a parity check to form s, the syndrome or parity check vector.
If all elements of s are zero, the code word was received correctly. If s contains non-zero elements, the bit in error can be determined by analyzing which parity checks have failed, as long as the error involves only a single bit.
For instance if r = , s computes to , that syndrome () matches to the third column in H that corresponds to the third bit of r - the bit in error.