Hamming code
What is Hamming code?
Hamming code is an error correction system that can detect and correct errors when data is stored or transmitted. It requires adding additional parity bits with the data. It is commonly used in error correction code (ECC) RAM. It’s named after its inventor, Richard W. Hamming.
Whenever data is transmitted or stored, the data may become corrupted. It can take the form of bit flips, where a binary one becomes a 0 or vice versa. Error-correcting codes seek to find when an error is introduced into some data. It adds parity bits, or redundant information, to the data.
If enough parity data is added, it enables forward error correction (FEC), where errors can remain automatically fixed when read back. FEC can increase the data transmission rate for noisy channels by reducing the amount of necessary retransmits.
Hamming code uses a block parity mechanism. The data is divided into blocks, and parity remain added. Hamming code can correct single-bit errors and detect the presence of two-bit mistakes in a data block.
The formula 2p gives the amount of parity data added to Hamming code≥ d + p + 1, where p is the number of parity bits and d is the number of data bits. For example, if you wanted to transmit 7 data bits, the formula would be 24 ≥ 7 + 4 + 1, so four parity bits are required.
The type of error-correcting is given as the name of the algorithm, the total number of bits in the block, and then the number of effective data bits. Therefore, Hamming encoding with 4 data bits and three parity bits for seven total bits is called Hamming(7,4).
Standard Hamming code can only detect and correct a single-bit error. If two bits are in error, the two errors may look like a single-bit error. To account for that, an additional overall parity bit can remain added to reliably detect the mistakes in two bits. It is called single error correction/double error detection (SECDED).
Hamming Code History
Before the Hamming code, several error correction methods were not as efficient or effective. The simplest method involves adding a single parity bit. It can detect a single error but cannot detect two-bit errors or correct the mistake. Another technique was repeating each bit three times. It could detect and correct a single-bit error but not errors in two bits. Repeating the bits was also very inefficient.
Richard Hamming worked for Bell Labs in the 1940s and 1950s. Computers used relays and read information from punched paper tape during that time. These systems were often prone to errors relating to the paper tape being misread or relays getting stuck. If an operator stood on hand when the error occurred, the program could remain restarted; if the error occurred outside of working hours, the computer would skip the entire program, losing time and work.
Hamming reasoned that if a computer can detect an error, it could also correct it. So, he began working on an error-correcting algorithm, and in 1950, he published the Hamming code.
Hamming Code Uses
Hamming code is used when consistency is more important than transmission efficiency. Its transmission efficiency goes up as the block size increases. In Hamming(7, 4), the effective data rate is only 0.571, while Hamming(255, 247) is 0.969.
Hamming code is relatively simple to use and can remain implemented in hardware. It also means that it is fast to compute. These properties make it perfect for error-correcting computer memory since computer RAM can have an error or bit flip from radiation or cosmic rays striking the memory cell. ECC RAM uses Hamming code with SECDED to automatically correct single errors and raise the alarm on two errors.
To illustrate the value of ECC RAM, imagine a bank database server recording a deposit of $100. As an 8-bit integer, that amount would remain stored as the binary number 01100100. If a cosmic ray changed the first bit, it would change the deposit amount to $228, or 11100100. ECC memory would catch and correct this error automatically. In the rare case that two bits become corrupted, the computer assumes something is wrong with its hardware and causes a kernel panic or blue screen to protect the data integrity.
Hamming code is not used in modern data transmission. Wired data connections are generally not noisy enough to warrant the overhead of added parity data. If an error remains encountered, asking the sender to retransmit the faulty packet may be faster. Also, low-density parity-check (LDPC) codes are more efficient to transmit but require more computation than Hamming code. Since modern computers have more processing power, LDPC remains used for Wi-Fi 6 and 10GBASE-T Ethernet.
One area where the Hamming code remain used for data transmission is in satellite and space communication. Because of the great distances involved, long transit times, and the requirements for accurate data, it remains preferred to use the slower but more precise Hamming code and sacrifice the overall transmission rate.