We are now in a position to actually write down the Hamming (7,4) code. As explained in the previous three entries, we want some way of both detecting that an error occurred and of correcting that error. As with many problems, this is much easier once you know it is possible (thanks, Richard Hamming!) In particular, last time we proved that it is *necessary *to send a 7-bit message in our scheme of correcting errors for a 4-bit message, but is it sufficient? An easy way to deduce the solution in this case (and then to see the pattern that proves the general case) is to require that our parity check detects the location of any 1-bit error.

Specifically, someone will receive a (possibly corrupt) 7-bit string **v**, and we want a matrix that will output **0** if all is well, or communicate a number 1-7 if one of the bits is corrupt. It takes 3 bits to communicate 8 numbers (8 = 2^{3}), so our parity matrix *H* (following wikipedia’s notation) must be 3 x 7. To make it easy to remember, we’ll even have column *j* be the binary representation for *j*. More directly:

Now we can work backwards (again, we’re *assuming* an answer exists), and for reasons that may be clear later, we’ll set our three parity bits to be the three “singleton” columns of *H*, so that the “coded” message **v =** (p1,p2,d1,p3,d2,d3,d4). Then if everything goes smoothly, we have that *H***v** = **0**, so that

0 = p1+d1+d2+d4

0 = p2+d1+d3+d4

0 = p3+d2+d3+d4.

Notice also that if one bit gets corrupted, this is equivalent to sending the message **v+e**_{j}, and

*G*(**v+e**_{j}) = **0+g**_{j},

where **g**_{j} is the *j*th column of *G* (which is the binary representation of the number *j*). Hence multiplying a message with a 1-bit mistake gives us the index of the corrupt bit.

But this tells us how we must *encode* our message **m = **(d1,d2,d3,d4) as well. We want a matrix *G* so that *G***m **= **v **= (p1,p2,d1,p3,d2,d3,d4). But the above gives us a linear condition for what this matrix must look like (and an explanation for why the parity bits are all “singletons”).

Finally we want to “decode” our message, which is also straightforward at this point, since it will just be the matrix which returns the non-parity bits from the encoded message.

As a review, and to wrap everything up:

1. Start with a message **m = **(1,0,0,1)

2. Transmit the message **v = ***G***m** = (0,0,1,1,0,0,1)

3. Check the parity by confirming that *H***v** = (0,0,0).

4. Decode the message R**v** = (1,0,0,1), as desired.

Wikipedia’s also got an explanation involving Venn diagrams which I did not much like, though I *may* write a bit about Venn diagrams themselves in the future…