Error correcting coding - Hamming code
Hamming code: can detect double- bit errors and correct single- bit errors.
work process
- Confirm the number of check code digits r
- Determine the location of the checksum and data
- Find the value of the check code
- Detect and correct errors
01 Confirm the number of check code digits r
Hamming's inequality: 2 r ≥ k + r + 1 k is the information bit, r is the redundant information bit\text{Hamming's inequality:} 2^r \geq k + r + 1 \\ k is the information bit, r is redundant information bitsHamming's inequality: 2r≥k+r+1k is the information bit , r is the redundant information bit
Principle :
There are a total of r bits of redundant information bits 2 r 2^r2r combinations, except for 1 whose identification information is correct, there are2 r − 1 2^r-12r−1 combination to identify2 r − 1 2^r - 12r−1 position error. Then there should be the number of identification error combinations >= the total number of transmitted bits, that is,2 r − 1 ≥ k + r 2^r - 1 \geq k + r2r−1≥k+r
02 Determine the location of the check code and data
Assume data D = 101101 D=101101D=101101
Then according to Hamming's inequality, r = 4 r = 4r=4
Let the check digits from left to right be P 1 , P 2 , P 3 , P 4 P_1, P_2, P_3, P_4P1、P2、P3、P4, the data from left to right are D 1 , D 2 , D 3 , D 4 , D 5 , D 6 D_1, D_2, D_3, D_4, D_5, D_6D1、D2、D3、D4、D5、D6
The check digits are placed in several powers of 2, and the data bits are filled in the empty bits from left to right.
Location | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
code | P 1 P_1 P1 | P 2 P_2 P2 | D 1 D_1 D1 | P 3 P_3 P3 | D 2 D_2 D2 | D 3 D_3 D3 | D 4 D_4 D4 | P 4 P_4 P4 | D 5 D_5 D5 | D 6 D_6 D6 |
actual value | 1 | 0 | 1 | 1 | 0 | 1 |
03 Find the value of the check code
Each check digit is filled in a power of 2 position, so its "binary representation of position" has only one 1, which is set in the r-th position from the right. This check digit verifies the data whose r-th bit from the right of the "position binary representation" is 1.
For example: P 1 P_1P1In the positional binary representation, 1 is in the first digit from the right, then it verifies all data whose first digit from the right in the "positional binary representation" is 1, that is, the 3rd, 5th, 7th, 9th... 3, 5, 7, 9 \ldots3、5、7、9... bits,P 2 P_2P2Check the 3rd, 6th, 7th, 10th... 3, 6, 7, 10 \ldots3、6、7、10... bits,P 3 P_3P3Check the 5th, 6th, 7th... 5, 6, 7 \ldots5、6、7... bits,P 4 P_4P4Check the 9th, 10th...9, 10th \ldots9、10… bit.
The parity bit should make the data in all parity positions XOR with itself to be 0 (can be understood as even parity).
P 1 ⊕ D 1 ⊕ D 2 ⊕ D 4 ⊕ D 5 = 0 ⟹ P 1 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 0 = 0 ⟹ P 1 = 0 P 2 ⊕ D 1 ⊕ D 3 ⊕ D 4 ⊕ D 6 = 0 ⟹ P 2 ⊕ 1 ⊕ 1 ⊕ 1 ⊕ 1 = 0 ⟹ P 2 = 0 P 3 ⊕ D 2 ⊕ D 3 ⊕ D 4 = 0 ⟹ P 3 ⊕ 0 ⊕ 1 ⊕ 1 = 0 ⟹ P 3 = 0 P 4 ⊕ D 5 ⊕ D 6 = 0 ⟹ P 4 ⊕ 0 ⊕ 1 = 0 ⟹ P 4 = 1 \begin{aligned} & P_1 \oplus D_1 \oplus D_2 \oplus D_4 \oplus D5 = 0 & \implies & P_1 \oplus 1 \oplus 0 \oplus 1 \oplus 0 = 0 & \implies P_1 = 0 \\ & P_2 \oplus D_1 \oplus D_3 \oplus D_4 \oplus D6 = 0 & \implies & P_2 \oplus 1 \oplus 1 \oplus 1 \ oplus 1 = 0 & \implies P_2 = 0 \\ & P_3 \oplus D_2 \oplus D_3 \oplus D_4 = 0 & \implies & P_3 \oplus 0 \oplus 1 \oplus 1 = 0 & \implies P_3 = 0 \\ & P_4 \oplus D_5 \oplus D_6 = 0 & \implies & P_4 \oplus 0 \oplusP1⊕D1⊕D2⊕D4⊕D5=0P2⊕D1⊕D3⊕D4⊕D6 _=0P3⊕D2⊕D3⊕D4=0P4⊕D5⊕D6=0⟹⟹⟹⟹P1⊕1⊕0⊕1⊕0=0P2⊕1⊕1⊕1⊕1=0P3⊕0⊕1⊕1=0P4⊕0⊕1=0⟹P1=0⟹P2=0⟹P3=0⟹P4=1
Fill in the resulting check digit value
Location | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
binary representation | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 |
code | P 1 P_1 P1 | P 2 P_2 P2 | D 1 D_1 D1 | P 3 P_3 P3 | D 2 D_2 D2 | D 3 D_3 D3 | D 4 D_4 D4 | P 4 P_4 P4 | D 5 D_5 D5 | D 6 D_6 D6 |
actual value | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
That is, the transmitted data is 0010 0111 01
04 Error detection and correction
Assume that the 5th bit during transmission is D 2 D_2D2An error occurred, the result received was 0010 1 111 01
Perform XOR calculation according to the check value method
P 1 ⊕ D 1 ⊕ D 2 ⊕ D 4 ⊕ D 5 = 0 ⊕ 1 ⊕ 1 ⊕ 1 ⊕ 0 = 1 P 2 ⊕ D 1 ⊕ D 3 ⊕ D 4 ⊕ D 6 = 0 ⊕ 1 ⊕ 1 ⊕ 1 ⊕ 1 = 0 P 3 ⊕ D 2 ⊕ D 3 ⊕ D 4 = 0 ⊕ 1 ⊕ 1 ⊕ 1 = 1 P 4 ⊕ D 5 ⊕ D 6 = 1 ⊕ 0 ⊕ 1 = 0 \ begin{aligned} & P_1 \oplus D_1 \oplus D_2 \oplus D_4 \oplus D5 & = & 0 \oplus 1 \oplus 1 \oplus 1 \oplus 0 & = 1 & \\ & P_2 \oplus D_1 \oplus D_3 \oplus D_4 \oplus D6 & = & 0 \oplus 1 \oplus 1 \oplus 1 \oplus 1 & = 0 \\ & P_3 \oplus D_2 \oplus D_3 \oplus D_4 & = & 0 \oplus 1 \oplus 1 \oplus 1 & = 1 \\ & P_4 \oplus D_5\oplus D_6 & = & 1 \oplus 0 \oplus 1 & = 0 \end{aligned}P1⊕D1⊕D2⊕D4⊕D5P2⊕D1⊕D3⊕D4⊕D6 _P3⊕D2⊕D3⊕D4P4⊕D5⊕D6====0⊕1⊕1⊕1⊕00⊕1⊕1⊕1⊕10⊕1⊕1⊕11⊕0⊕1=1=0=1=0
The result of sorting from bottom to top is 0101, which corresponds to decimal 5, that is, the 5th bit is wrong, just change it from 1 to 0.
Note: Both single-bit and double-bit errors can be detected, but only single-bit errors can be corrected. If a double-bit error occurs, the Hamming code check result can only indicate an error, that is, the check result is not all 0, but the corresponding position is not necessarily wrong. In this case, the Hamming code defaults to a single-bit error and is corrected. , there will be error correction and error problems.
Principle : When a certain check bit error detection XOR output is 1, it means that the position of the "position binary representation" of the error bit must be 1. If the XOR output is 0, it means that the position of the "position binary representation" of the error bit must be 1. The position is 0. Then the check results sorted from bottom to top exactly represent the "position binary representation" of the error bit.
My personal understanding. If there are any mistakes or you have a better understanding, please correct me.
The above are personal study notes, study video link B Station-Wangdao Postgraduate Entrance Examination-Computer Network