Hamming code
(communications) An error-correcting code used in data transmission.
|
Results for Hamming code
|
On this page:
|
(communications) An error-correcting code used in data transmission.
An error correction method that intersperses three check bits at the end of each four data bits. At the receiving station, the check bits are used to detect and correct one-bit errors automatically.
In telecommunication, a Hamming code is a linear error-correcting code named after its inventor, Richard Hamming. Hamming codes can detect and correct single-bit errors. In other words, the Hamming distance between the transmitted and received code-words must be zero or one for reliable communication.
In contrast, the simple parity code cannot detect errors where two bits are transposed, nor can it correct the errors it can find.
In mathematical terms, Hamming codes are a class of binary linear codes. For each integer m > 1 there is a code with parameters: [2m - 1,2m - m - 1,3]. The parity-check matrix of a Hamming code is constructed by listing all columns of length m that are pair-wise independent.
Because of the simplicity of Hamming codes, they are widely used in computer memory (RAM). In particular, a single-error-correcting and double-error-detecting variant commonly referred to as SECDED.
Hamming worked at Bell Labs in the 1940s on the Bell Model V computer, an electromechanical relay-based machine with cycle times in seconds. Input was fed in on punch cards, which would invariably have read errors. During weekdays, special code would find errors and flash lights so the operators could correct the problem. During after-hours periods and on weekends, when there were no operators, the machine simply moved on to the next job.
Hamming worked on weekends, and grew increasingly frustrated with having to restart his programs from scratch due to the unreliability of the card reader. Over the next few years he worked on the problem of error-correction, developing an increasingly powerful array of algorithms. In 1950 he published what is now known as Hamming Code, which remains in use in some applications today.
A number of simple error-detecting codes were used before Hamming codes, but none were as effective as Hamming codes in the same overhead of space.
Parity adds a single bit that indicates whether the number of 1 bits in the preceding data was even or odd. If a single bit is changed in transmission, the message will change parity and the error can be detected at this point. (Note that the bit that changed may have been the parity bit itself!) The most common convention is that a parity value of 1 indicates that there is an odd number of ones in the data, and a parity value of 0 indicates that there is an even number of ones in the data. In other words: The data and the parity bit together should contain an even number of 1s.
Parity checking is not very robust, since if the number of bits changed is even, the check bit will be valid and the error will not be detected. Moreover, parity does not indicate which bit contained the error, even when it can detect it. The data must be discarded entirely and re-transmitted from scratch. On a noisy transmission medium, a successful transmission could take a long time or may never occur. However, while the quality of parity checking is poor, since it uses only a single bit, this method results in the least overhead. Furthermore, parity checking does allow for the restoration of a missing bit when the missing bit is known.
In the 1940s Bell used a slightly more sophisticated m of n code known as the two-out-of-five code. This code ensured that every block of five bits (known as a 5-block) had exactly two 1s. The computer could tell if there was an error if in its input there were not exactly two 1s in each block. Two-of-five was still only able to detect single bits; if one bit flipped to a 1 and another to a 0 in the same block, the two-of-five rule remained true and the error would go undiscovered.
Another code in use at the time repeated every data bit several times in order to ensure that it got through. For instance, if the data bit to be sent was a 1, an n=3 repetition code would send "111". If the three bits received were not identical, an error occurred. If the channel is clean enough, most of the time only one bit will change in each triple. Therefore, 001, 010, and 100 each correspond to a 0 bit, while 110, 101, and 011 correspond to a 1 bit, as though the bits counted as "votes" towards what the original bit was. A code with this ability to reconstruct the original message in the presence of errors is known as an error-correcting code.
Such codes cannot correctly repair all errors, however. In our example, if the channel flipped two bits and the receiver got "001", the system would detect the error, but conclude that the original bit was 0, which is incorrect. If we increase the number of times we duplicate each bit to four, we can detect all two-bit errors but can't correct them (the votes "tie"); at five, we can correct all two-bit errors, but not all three-bit errors.
Moreover, the repetition code is extremely inefficient, reducing throughput by three times in our original case, and the efficiency drops drastically as we increase the number of times each bit is duplicated in order to detect and correct more errors.
If more error-correcting bits are included with a message, and if those bits can be arranged such that different incorrect bits produce different error results, then bad bits could be identified. In a 7-bit message, there are seven possible single bit errors, so three error control bits could potentially specify not only that an error occurred but also which bit caused the error.
Hamming studied the existing coding schemes, including two-of-five, and generalized their concepts. To start with he developed
a nomenclature to describe the system,
including the number of data bits and error-correction bits in a block. For instance, parity includes a single bit for any data
word, so assuming
Hamming also noticed the problems with flipping two or more bits, and described this as the "distance" (it is now called the Hamming distance, after him). Parity has a distance of 2, as any two bit flips will be invisible. The (3,1) repetition has a distance of 3, as three bits need to be flipped in the same triple to obtain another code word with no visible errors. A (4,1) repetition (each bit is repeated four times) has a distance of 4, so flipping two bits can be detected, but not corrected. When three bits flip in the same group there can be situations where the code corrects towards the wrong code word.
Hamming was interested in two problems at once; increasing the distance as much as possible, while at the same time increasing the information rate as much as possible. During the 1940s he developed several encoding schemes that were dramatic improvements on existing codes. The key to all of his systems was to have the parity bits overlap, such that they managed to check each other as well as the data.
Although any number of algorithms can be created, the following general algorithm positions the parity bits at powers of two to ease calculation of which bit was flipped upon detection of incorrect parity.
In other words, the parity bit at position 2k checks bits in positions having bit k set in their binary representation. Conversely, for instance, bit 13, i.e. 1101(2), is checked by bits 1000(2) = 8, 0100(2)=4 and 0001(2) = 1.
Hamming codes have a minimum distance of 3, which means that the code can detect and correct a single error, but a double bit error is indistinguishable from a different code with a single bit error. Thus, they can detect double-bit errors only if correction is not attempted.
By including an extra parity bit, then it is possible to increase the minimum distance of the Hamming code to 4. This gives the code the ability to detect and correct a single error and at the same time detect (but not correct) a double error. (It could also be used to detect up to 3 errors but not correct any.)
This code system is popular in computer memory systems, where it is known as SECDED ("single error correction, double error detection"). Particularly popular is the (72,64) code, a truncated (127,120) Hamming code plus an additional parity bit, which has the same space overhead as a (9,8) parity code.
In general, if the minimum distance of any error correction code is given by W, then Failed to parse (unknown function\tfrac): \left \lfloor \tfrac{W}{2} \right \rfloor
errors are detectable, Failed to parse (unknown function\tfrac): \left \lfloor \tfrac{W-1}{2} \right \rfloor
of which are correctable.
In 1950, Hamming introduced the (7,4) code. It encodes 4 data bits into 7 bits by adding three parity bits. Hamming(7,4) can detect and correct single-bit errors but can only detect double-bit errors.
The code generator matrix
and the parity-check matrix
are:

and

For example, 1011 is encoded into 0110011 where blue digits are data and red digits are parity.
The Hamming(7,4) can easily be extended to an (8,4) code by adding an extra parity bit on top of the (7,4) encoded word (see above section). This can be summed up in a revised parity-check matrix:

The addition of the fourth row computes the sum of all bits (data and parity) as the fourth parity bit.
For example, 1011 is encoded into 01100110 where blue digits are data; red digits are parity from
the Hamming(7,4) code; and the green digit is the parity added by Hamming(8,4). The green digit makes the parity of the (7,4)
code even.
Consider the 7-bit data word "0110101". To demonstrate how Hamming codes are calculated and used to detect an error, see the tables below. They use d to signify data bits and p to signify parity bits.
Firstly the data bits are inserted into their appropriate positions and the parity bits calculated in each case using even parity. The diagram to the right shows which of the four parity bits cover which data bits.
| p1 | p2 | d1 | p3 | d2 | d3 | d4 | p4 | d5 | d6 | d7 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Data word (without parity): | 0 | 1 | 1 | 0 | 1 | 0 | 1 | ||||
| p1 | 1 | 0 | 1 | 0 | 1 | 1 | |||||
| p2 | 0 | 0 | 1 | 0 | 0 | 1 | |||||
| p3 | 0 | 1 | 1 | 0 | |||||||
| p4 | 0 | 1 | 0 | 1 | |||||||
| Data word (with parity): | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
The new data word (with parity bits) is now "10001100101". We now assume the final bit gets corrupted and turned from 1 to 0. Our new data word is "10001100100"; and this time when we analyse how the Hamming codes were created we flag each parity bit as 1 when the even parity check fails.
| p1 | p2 | d1 | p3 | d2 | d3 | d4 | p4 | d5 | d6 | d7 | Parity check | Parity bit | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Received data word: | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | ||
| p1 | 1 | 0 | 1 | 0 | 1 | 0 | Fail | 1 | |||||
| p2 | 0 | 0 | 1 | 0 | 0 | 0 | Fail | 1 | |||||
| p3 | 0 | 1 | 1 | 0 | Pass | 0 | |||||||
| p4 | 0 | 1 | 0 | 0 | Fail | 1 |
The final step is to evaluate the value of the parity bits (remembering the bit with lowest index is the least significant bit, i.e., it goes furthest to the right). The integer value of the parity bits is 11, signifying that the 11th bit in the data word (including parity bits) is wrong and needs to be flipped.
| p4 | p3 | p2 | p1 | ||
|---|---|---|---|---|---|
| Binary | 1 | 0 | 1 | 1 | |
| Decimal | 8 | 2 | 1 | Σ = 11 |
Flipping the 11th bit changes 10001100100 back into 10001100101. Removing the Hamming codes gives the original data word of 0110101.
Note that as parity bits do not check each other, if a single parity bit check fails and all others succeed, then it is the parity bit in question that is wrong and not any bit it checks.
Finally, suppose two bits change, at positions x and y. If x and y have the same bit at the 2k position in their binary representations, then the parity bit corresponding to that position checks them both, and so will remain the same. However, some parity bit must be altered, because x ≠ y, and so some two corresponding bits differ in x and y. Thus, the Hamming code detects all two bit errors — however, it cannot distinguish them from 1-bit errors.
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
Some good "Hamming code" pages on the web:
Math mathworld.wolfram.com |
Join the WikiAnswers Q&A community. Post a question or answer questions about "Hamming code" at WikiAnswers.
Copyrights:
![]() | Sci-Tech Dictionary. McGraw-Hill Dictionary of Scientific and Technical Terms. Copyright © 2003, 1994, 1989, 1984, 1978, 1976, 1974 by McGraw-Hill Companies, Inc. All rights reserved. Read more | |
![]() | Computer Desktop Encyclopedia. THIS COPYRIGHTED DEFINITION IS FOR PERSONAL USE ONLY. All other reproduction is strictly prohibited without permission from the publisher. © 1981-2008 Computer Language Company Inc. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Hamming code". Read more |