Hamming Code
Hamming Code
Hamming Code
Implement the Data Link layer error detection and correction techniques using
Hamming Code.
Procedure:
Hamming code is a popular error detection and error correction method in data communication.
Hamming code can only detect 2 bit error and correct a single bit error which means it is unable to
correct burst errors if may occur while transmission of data.
Hamming code uses redundant bits (extra bits) which are calculated according to the below
formula:-
2r ≥ m+r+1
Where r is the number of redundant bits required and m is the number of data bits.
R is calculated by putting r = 1, 2, 3 … until the above equation becomes true.
R1 bit is appended at position 20
R2 bit is appended at position 21
R3 bit is appended at position 22 and so on.
These redundant bits are then added to the original data for the calculation of error at receiver’s
end.
At receiver’s end with the help of even parity (generally) the erroneous bit position is identified
and since data is in binary we take complement of the erroneous bit position to correct received
data.
Respective index parity is calculated for r1, r2, r3, r4 and so on.
output:
Hamming code-----Encoding
Enter 4 bit data:1011
Generator matrix:
0111000
1010100
1100010
1110001
Encoded data:0101011
Hamming code---Decoding
Enter encoded bits as received:0 1 0 1 0 1 1
syndrome:0 syndrome:0 syndrome:0
error free
Hamming code-----Encoding
Enter 4 bit data:1011
Generator matrix:
0111000
1010100
1100010
1110001
Encoded data:0101011
Hamming code---Decoding
Enter encoded bits as received:0 1 0 1 1 1 1
syndrome:1 syndrome:0 syndrome:1
error received at bit number 5 of data
correct data should be:0101011