Hamming code notes

Error correcting coding - Hamming code

Hamming code: can detect double- bit errors and correct single- bit errors.

work process

  1. Confirm the number of check code digits r
  2. Determine the location of the checksum and data
  3. Find the value of the check code
  4. 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: 2rk+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-12r1 combination to identify2 r − 1 2^r - 12r1 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 + r2r1k+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_4P1P2P3P4, 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_6D1D2D3D4D5D6

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 \ldots3579... bits,P 2 P_2P2Check the 3rd, 6th, 7th, 10th... 3, 6, 7, 10 \ldots36710... bits,P 3 P_3P3Check the 5th, 6th, 7th... 5, 6, 7 \ldots567... bits,P 4 P_4P4Check the 9th, 10th...9, 10th \ldots910 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 \oplusP1D1D2D4D5=0P2D1D3D4D6 _=0P3D2D3D4=0P4D5D6=0P11010=0P21111=0P3011=0P401=0P1=0P2=0P3=0P4=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}P1D1D2D4D5P2D1D3D4D6 _P3D2D3D4P4D5D6====01110011110111101=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

Guess you like

Origin blog.csdn.net/qq_44856695/article/details/105350019