Hamming code
Hamming code
Hamming code is a error-correcting code used in digital communications. It detects and corrects
errors that may occur during data transmission. It was introduced by Richard Hamming in the 1940s
and is widely used today.
The fundamental concept behind Hamming code is adding redundant bits to the original data bits.
This can further be used to detect and correct errors during transmission. The number of redundant
bits added depends on the size of the data being transmitted and the level of error correction
required.
Hamming Code plays a crucial role in computer networks for ensuring data integrity and reliability in
data transmission. Here's why it's essential:
• Error Detection and Correction: Hamming Code enables the detection and correction of
errors that may occur during data transmission. In network communication, data can get
corrupted due to various factors such as electrical noise, interference, or hardware failures.
Hamming Code detects errors and, in many cases, corrects them without the need for
retransmission, improving the overall reliability of the network.
• Reduced Latency: Retransmitting data packets due to errors can introduce latency and
reduce the overall efficiency of the network. By using Hamming Code for error detection and
correction, networks can minimize the need for retransmissions, leading to reduced latency
and improved response times for network applications.
• Data Integrity: Ensuring data integrity is crucial in computer networks, especially in critical
applications such as financial transactions, healthcare systems, and military communications.
Hamming Code helps maintain data integrity by detecting and correcting errors, thereby
preventing data corruption and ensuring that transmitted data remains accurate and reliable.
Before understanding the working and general algorithm of hamming code, it is vital to know specific
essential terms related to the Hamming code example discussed in the article.
1. Error-correcting code
A code used in digital communications to detect and correct errors parallelly that occur during data
transmission.
2. Redundant bits
The extra bits added to a message to enable error detection and correction. Hamming code uses
redundancy to detect and correct errors in transmitted messages
The redundant bits are assigned to positions that coincide with the power of 2. Ex, 2^p (where
p=0,1,2,3…)
4. Parity bit
An extra bit added to a message to check for errors. The number of 1s in the message finds the parity
bit's value.
5. Single-bit error
An error that occurs when only one bit of a message is incorrect. Hamming code can detect and
correct single-bit errors.
6. Hamming distance
Hamming distance is the count of the number of bit positions in which two code messages differ.
Hamming distance is used to find the minimum number of parity bits required for error detection
and correction.
7. Generator matrix
A matrix used to generate the parity bits for a Hamming code. The generator matrix calculates the
parity bits for a given code word.
8. Check matrix
A matrix used to check for errors in a Hamming code. The check matrix calculates the syndrome for a
given received message.
9. Burst error
An error that occurs when multiple bits in a message are incorrect. Hamming code is not able to
correct burst errors. It only detects them.
Hamming code is an error correction code used in digital communication, data storage, and
computer memory systems.Next, let us look at the working of hamming code by algorithm and
example.
Generic Algorithm
The Hamming code creates parity bits that cover different subsets of the original data bits. The parity
bits are then used to check for errors in the transmission. If an error is detected, the code can use
the parity bits to determine which bit is in error and correct it.
The systemic method to generate Hamming code can be explained in the following steps:
1. Find the number of redundant bits' r' needed with the expression 2^r>=d+r+1. Here d
represents the data bits.
2. Next, the respective positions are assigned to each bit in Hamming code, starting from the
leftmost bit as position 1, followed by the next bit as position 2, and so on.
3. Next, the position of the parity bits is determined by selecting the positions that have 1 in a
binary representation of their number.
4. In this step, the value of each parity bit is calculated based on the value of data bits assigned
to it.
5. Next, the calculated parity bits are inserted into the Hamming code at their corresponding
positions, after which the Hamming code is transmitted to the receiver.
6. The receiver checks the Hamming code by calculating the parity bits using the same
algorithm as the transmitter.
7. A data bit can be rectified by flipping its value if an error is detected. If the error lies in the
parity bit, the bit can be ignored.
• Memory System Use: Common in ECC memory systems for data integrity.
• Limited Burst Error Handling: Best for single-bit errors; limited for burst errors.
• Suppose we have a 4-bit message that we want to transmit: 111011. Now we apply the
above steps in this hamming code example.
=> 2^r>=r+7
• Thus we will use a Hamming code with four parity bits, which requires a 10-bit code word.
We place the message bits in positions 3, 5, 6, 7, 9, and 10 of the code word and the parity
bits in positions 1, 2, 4, and 8, as shown below:
• For r1: bit positions 1,3,5,7,9. The positions are identified by selecting only those bit indexes
whose binary form includes a 1 in the least significant bit position.
As the number of 1's at all bit positions corresponding to r1 is odd, the value of r1=1
• Similarly, we calculate r2 with the help of a parity check. The positions are identified by
selecting only those bit indexes whose binary form includes a 1 in the 2nd index from the
least significant bit. Thus the bit positions are 2, 3, 6, 7, and 10, and the corresponding value
for r2=1, considering even parity.
• Similarly, for r3: The positions are identified by selecting only those bit indexes whose binary
form includes a 1 in the 3rd index from the least significant bit. Bit positions are 4, 5, 6, and 7
with the value of r4=0 to satisfy even parity.
• For r4: The positions are identified by selecting only those bit indexes whose binary form
includes a 1 in the 4th index from the least significant bit. Bit positions are 8, 9 and 10 with
the value of r8=0 to satisfy even parity.
• Now putting all the parity bit values in the message, we get the Hamming code as
1110110011 for this hamming code example.
• Assuming that there is an error during transmission in the above hamming code example,
and the data bit at position 5 changes from 1 to 0. Thus the message received is
1110010011. The error can be detected using the same parity bit technique. Therefore we
get the parity value at r1, r2, r4 and r8 as 1, 0, 1, and 0. Since the parity values obtained are
different from that of the original values, an error is detected.
• To locate the position of the error bit, we use the new parity values [2^0+0+2^2+0] = 5, i.e.,
the assumed error bit position.
• To rectify the error bit, its value is reversed. If the error bit value is 1, we flip it to 0 and vice
versa. Hence the value of the bit at the 5th position is reversed to 1.
Applications of hamming code range widely from computer memory to medical imaging
• Computer memory: Hamming code is one of the most popular error-handling codes used in
the computer memory system to detect and rectify errors during data transmission.
• Satellite Communication: While sending and receiving signals via satellites, errors can occur
due to atmospheric changes and other environmental factors. Hamming code can detect and
correct these errors, ensuring reliable satellite and ground station communication.
• Medical Applications: Accurate data transmission is critical for disease diagnosis in medical
applications, such as MRI and CT scans. Here, hamming code detects and corrects errors that
may occur during data transmission, ensuring that the diagnostic results are accurate.
• Detection and Correction of Errors: One of the main advantages of Hamming code is its
ability to detect and correct errors in transmitted data. With the addition of extra bits to the
message being transmitted, the receiver can compare the received message with the original
message and determine the occurrence of errors. If errors are detected, the receiver uses
extra bits to correct them.
• Efficiency: Hamming code can correct a single-bit error in a message of any size. It does not
require additional bandwidth or processing power to implement and is easy to understand
and use. Hence it is considered an efficient error-correcting code.
• Redundancy: Redundancy in Hamming code involves adding extra bits to data, enabling
error detection and correction by comparing received and expected data patterns.
• Low Complexity: Hamming code does not require extensive memory or processing power.
Hence it is a simple and low-complexity error-correcting code that can be implemented in
hardware or software.
• Versatile: Hamming code can be used for both error detection and correction. This versatility
makes it a valuable tool in many applications where error-free data transmission is
important.
• Hamming code cannot be used to detect and resolve multiple bit errors. It is suitable for only
single bit errors. Thus it is not suitable for applications that require a high level of error
correction.
• Hamming code requires a significant amount of additional data bits to be added to the
original message for it to function properly. This redundancy increases overall transmission
time and bandwidth usage.
• Hamming code is not secure as it can only detect errors that occur unintentionally during
data transmission.
When data transmission takes place, some parts of the message get corrupted due to noise and data
leaks. A code used in digital communications to detect and correct errors parallelly that occur during
data transmission is known as an error correction code.
During data transmission, if the message received differs from the original message by two bits, it is
known as a 2-bit error. Hamming code can be used to detect a 2-bit error in a code.
Hamming numbers, also known as ugly numbers, are numbers with only prime factors of 2, 3, or 5.
The first 20 Hamming numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, and
36.