In coding theory, Hamming(7,4) is a linear error-correcting code that encodes four bits of data into seven bits by adding three parity bits. It is a member of a larger family of Hamming codes, but the term Hamming code often refers to this specific code that Richard W. Hamming introduced in 1950. At the time, Hamming worked at Bell Telephone Laboratories and was frustrated with the error-prone punched card reader, which is why he started working on error-correcting codes. The Hamming code adds three additional check bits to every four data bits of the message. Hamming's (7,4) algorithm can correct any single-bit error, or detect all single-bit and two-bit errors. In other words, the minimal Hamming distance between any two correct codewords is 3, and received words can be correctly decoded if they are at a distance of at most one from the codeword that was transmitted by the sender. This means that for transmission medium situations where burst errors do not occur, Hamming's (7,4) code is effective (as the medium would have to be extremely noisy for two out of seven bits to be flipped). In quantum information, the Hamming (7,4) is used as the base for the Steane code, a type of CSS code used for quantum error correction.
Goal The goal of the Hamming codes is to create a set of parity bits that overlap so that a single-bit error in a data bit or a parity bit can be detected and corrected. While multiple overlaps can be created, the general method is presented in Hamming codes.
This table describes which parity bits cover which transmitted bits in the encoded word. For example, p2 provides an even parity for bits 2, 3, 6, and 7. It also details which transmitted bit is covered by which parity bit by reading the column. For example, d1 is covered by p1 and p2 but not p3 This table will have a striking resemblance to the parity-check matrix (H) in the next section. Furthermore, if the parity columns in the above table were removed
then resemblance to rows 1, 2, and 4 of the code generator matrix (G) below will also be evident. So, by picking the parity bit coverage correctly, all errors with a Hamming distance of 1 can be detected and corrected, which is the point of using a Hamming code.
Hamming matrices Hamming codes can be computed in linear algebra terms through matrices because Hamming codes are linear codes. For the purposes of Hamming codes, two Hamming matrices can be defined: the code generator matrix G and the parity-check matrix H:
𝐆𝐓:=(1101101110000111010000100001),𝐇:=(101010101100110001111).
As mentioned above, rows 1, 2, and 4 of G should look familiar as they map the data bits to their parity bits:
p1 covers d1, d2, d4 p2 covers d1, d3, d4 p3 covers d2, d3, d4 The remaining rows (3, 5, 6, 7) map the data to their position in encoded form and there is only 1 in that row so it is an identical copy. In fact, these four rows are linearly independent and form the identity matrix (by design, not coincidence). Also as mentioned above, the three rows of H should be familiar. These rows are used to compute the syndrome vector at the receiving end and if the syndrome vector is the null vector (all zeros) then the received word is error-free; if non-zero then the value indicates which bit has been flipped. The four data bits — assembled as a vector p — is pre-multiplied by G (i.e., GTp) and taken modulo 2 to yield the encoded value that is transmitted. The original 4 data bits are converted to seven bits (hence the name "Hamming(7,4)") with three parity bits added to ensure even parity using the above data bit coverages. The first table above shows the mapping between each data and parity bit into its final bit position (1 through 7) but this can also be presented in a Venn diagram. The first diagram in this article shows three circles (one for each parity bit) and encloses data bits that each parity bit covers. The second diagram (shown to the right) is identical but, instead, the bit positions are marked. For the remainder of this section, the following 4 bits (shown as a column vector) will be used as a running example:
𝐩=(d1d2d3d4)=(1011)
Channel coding
Suppose we want to transmit this data (1011) over a noisy communications channel. Specifically, a binary symmetric channel meaning that error corruption does not favor either zero or one (it is symmetric in causing errors). Furthermore, all source vectors are assumed to be equiprobable. We take the product of G and p, with entries modulo 2, to determine the transmitted codeword x:
𝐱=𝐆𝐓𝐩=(1101101110000111010000100001)(1011)=(2312011)=(0110011) This means that 0110011 would be transmitted instead of transmitting 1011. The matrix multiplication occurs mod 2. Equivalently, each row of the result is the least significant bit of the Population Count of set bits resulting from the row and column being Bitwise ANDed together. In the adjacent diagram, the seven bits of the encoded word are inserted into their respective locations; from inspection it is clear that the parity of the red, green, and blue circles are even:
red circle has two 1's green circle has two 1's blue circle has four 1's What will be shown shortly is that if, during transmission, a bit is flipped then the parity of two or all three circles will be incorrect and the errored bit can be determined (even if one of the parity bits) by knowing that the parity of all three of these circles should be even.
Parity check If no error occurs during transmission, then the received codeword r is identical to the transmitted codeword x:
𝐫=𝐱 The receiver multiplies H and r to obtain the syndrome vector z, which indicates whether an error has occurred, and if so, for which codeword bit. Performing this multiplication (again, entries modulo 2):
𝐳=𝐇𝐫=(101010101100110001111)(0110011)=(242)=(000) Since the syndrome z is the null vector, the receiver can conclude that no error has occurred. This conclusion is based on the observation that when the data vector is multiplied by G, a change of basis occurs into a vector subspace that is the kernel of H. As long as nothing happens during transmission, r will remain in the kernel of H and the multiplication will yield the null vector.
Error correction Otherwise, suppose, we can write
𝐫=𝐱+𝐞i modulo 2, where ei is the ith unit vector, that is, a zero vector with a 1 in the ith, counting from 1.
𝐞2=(0100000) Thus the above expression signifies a single bit error in the ith place. Now, if we multiply this vector by H:
… excerpt ends here. Continue reading the full article.





