The hamming code technique in Computer Networks, which is an error-detection and error-correction technique, was proposed by R.W. Hamming. Whenever a data packet is transmitted over a network, there are possibilities that the data bits may get lost or damaged during transmission.
What is Hamming Code?
Let's understand the Hamming code concept with an example:
Let's say you have received a 7-bit Hamming code which is 1011011
. There are some extra binary bits that are not part of the original data which are called redundant bits, but they are generated & added to the original data bit. All this is done to ensure that the data bits don't get damaged and if they do, we can recover them.
Now the question arises, how do we determine the number of redundant bits added?
We use the formula, 2r >= m+r+1;
where r = redundant bit & m = data bit. From the formula we can make out that there are 4 data bits and 3 redundancy bits, referring to the received 7-bit hamming code.
What is a Parity Bit?
To proceed further we need to know about the parity bit, which is a bit appended to the data bits which ensures that the total number of 1's are even (even parity) or odd (odd parity).
While checking the parity, if the total number of 1's is odd then write the value of parity bit P1(or P2 etc.) as 1 (which means the error is there ), and if it is even then the value of parity bit is 0 (which means no error).
Hamming Code in Computer Network For Error Detection
As we go through the example, the first step is to identify the bit position of the data & all the bit positions which are powers of 2 are marked as parity bits (e.g. 1, 2, 4, 8, etc.). The following image will help in visualizing the received hamming code of 7 bits.
First, we need to detect whether there are any errors in this received hamming code.
Step 1: For checking parity bit P1, use the check one and skip one method, which means, starting from P1 and then skip P2, take D3 then skip P4 then take D5, and then skipping D6 and take D7, this way we will have the following bits,
As we can observe the total number of bits is odd so we will write the value of the parity bit as P1 = 1. This means an error is there.
Step 2: Check for P2 but while checking for P2, we will use check two and skip two methods, which will give us the following data bits. But remember since we are checking for P2, so we have to start our count from P2 (P1 should not be considered).
As we can observe that the number of 1's are even, then we will write the value of P2 = 0. This means there is no error.
Step 3: Check for P4 but while checking for P4, we will use the check four and skip four methods, which will give us the following data bits. But remember since we are checking for P4, so we have started our count from P4(P1 & P2 should not be considered).
As we can observe that the number of 1's is odd, then we will write the value of P4 = 1. This means the error is there.
So, from the above parity analysis, P1 & P4 are not equal to 0, so we can clearly say that the received hamming code has errors.
Hamming Code in Computer Network For Error Correction
Since we found that the received code has an error, so now we must correct them. To correct the errors, use the following steps:
Now the error word E will be:
Now we have to determine the decimal value of this error word 101 which is 5 (22 *1 + 21 * 0 + 20 *1 = 5).
We get E = 5, which states that the error is in the fifth data bit. To correct it, just invert the fifth data bit.
So the correct data will be:
Hamming Distance
Hamming distance is a metric for comparing two binary data strings. While comparing two binary strings of equal length, Hamming distance is the number of bit positions in which the two bits are different.
The Hamming distance between two strings, a and b is denoted as d(a,b).
It is used for error detection or error correction when data is transmitted over computer networks. It is also using in coding theory for comparing equal length data words.
Calculation of Hamming Distance
In order to calculate the Hamming distance between two strings, and , we perform their XOR operation, (a⊕ b), and then count the total number of 1s in the resultant string.
Example
Suppose there are two strings 1101 1001 and 1001 1101.
11011001 ⊕ 10011101 = 01000100. Since, this contains two 1s, the Hamming distance, d(11011001, 10011101) = 2.
Minimum Hamming Distance
In a set of strings of equal lengths, the minimum Hamming distance is the smallest Hamming distance between all possible pairs of strings in that set.
Example
Suppose there are four strings 010, 011, 101 and 111.
010 ⊕ 011 = 001, d(010, 011) = 1.
010 ⊕ 101 = 111, d(010, 101) = 3.
010 ⊕ 111 = 101, d(010, 111) = 2.
011 ⊕ 101 = 110, d(011, 101) = 2.
011 ⊕ 111 = 100, d(011, 111) = 1.
101 ⊕ 111 = 010, d(011, 111) = 1.
Hence, the Minimum Hamming Distance, dmin = 1.
0 Comments