Error Correcting Codes
The (7,4) Hamming code uses four data bits and three parity bits (for a total of seven bits). Suppose the data bits are b1b2b3b4. We set the parity bit p123 so b1b2b3p123 has even parity. Then we set the parity bit p124 so b1b2b4p124 has even parity. Finally we set the parity bit p134 so b1b3b4p134 has even parity. We then encode our results as b1b2b3b4p123p124p134. We can write this in terms of matrices as
Let's look at an example. Suppose our four data bits are 0110. Then we compute the parity bits p123 = 0, p124 = 1, and p134 = 1, and we get our seven-bit result 0110011. To test this sequence for errors, we check the parity of the sets b1b2b3p123, b1b2b4p124, and b1b3b4p134, which in this case are 0110, 0101, and 0101 respectively. Since all three have even parity, we detect no errors. Now suppose an error changes our seven-bit sequence to 0111011. This time when we look at the sets b1b2b3p123, b1b2b4p124, and b1b3b4p134, we get 0110, 0111, and 0111 respectively. Since two of these have odd parity, we detect an error. Looking at which sequences have errors, we see that we have detected no error in b1b2b3p123, but we have detected an error in b1b2b4p124, and b1b3b4p134. Assuming that there is only a single error (which we hope is more likely than there being two errors), we can conclude that the error is in bit b4, since it is the only bit that is in both sets b1b2b4p124 and b1b3b4p134 but not in b1b2b3p123. So we switch bit b4 in the errant sequence 0111011 from a 1 to a 0 to get back to the correct seven-bit sequence 0110011. Extracting the four data bits, we finally get 0110, which is what we started this paragraph with.
Since every bit, both data and parity, is in at least one of the sets b1b2b3p123, b1b2b4p124, and b1b3b4p134, any change in a single bit will foul up at least one of the three parity checks. On the other hand, since no two bits are in exactly the same parity checks, we can always determine which single bit was changed by examining which parity checks fail.