Checksum Test Example

Code distance: For a single code A:00, its code distance is 1, because it only needs to change one bit to become another code. In the two codes, the number of bits that need to be changed from A code to B code is called code distance. For example, if A:00 is converted to B:11, the code distance is 2. Generally speaking, the larger the code distance, the more conducive to error correction and error detection.

Parity check code: Add 1 check code bit in the encoding to make the number of 1 bits in the encoding odd (odd check) or even (even check), so that the code distance is shifted by 2.

Odd check: The code contains an odd number of 1s and is sent to the receiver. After the receiver receives it, it will calculate how many 1s there are in the received code. If it is an odd number, it is correct. error.

The same is true for the even check, except that there are even 1s in the code. From the above, the parity check can only detect 1 bit error and cannot correct it.

Cyclic Redundancy Check Code CRC

CRC can only detect errors, but cannot correct them. The principle is to find a code that can divide the polynomial. Therefore, first divide the original message by the polynomial, and add the remainder as the check digit to the original message. The data is sent to the receiver, and its encoding format is:

Bits 1 to r are parity bits, bits r+1 to n are data bits

It can be seen from the second that the CRC consists of two parts, the left side is the information code (original data), and the right side is the check code. The check code is generated by the information code. The longer the check code digits, the longer the check code digits, and the stronger the check ability. To find the CRC code is, the modulo 2 operation is used (bitwise operation, no borrow and carry occur)

For example: the original message is "1100 1010 101", its production polynomial is: X^4+ X^3+X+1, what is the result of CRC encoding after alignment?

Analytical solution: First, obtain the divisor 11011 according to the polynomial, add the number of 0s with the highest exponent of the polynomial after the original polynomial, that is, 4 0s, (x^4), and divide by modulo 2 with the divisor, always quotient 1, and finally get 4 digits remainder 0011

Final code: 1100 1010 101 0011

The receiver will calculate the received data with the polynomial modulo 2. If the remainder is 0, it means that the check code is correct and the data transmission is correct.

Hamming check code

Hamming code: In essence, it is also an inspection method that uses parity to detect and correct errors. The method consists of inserting K check bits at certain positions between data, and realizing error detection and correction by overextending the code distance.

Suppose the data bits are n bits and the check bits are k, then n and k must satisfy the following relationship: 2^K>= n+k

For example: Find the Hamming code of message 1011

Analysis steps:

The relationship between the number of parity bits and the number of bits of specific data bits, all bits are numbered, numbered from the lowest bit, and incremented from 1, the parity bit is at n of 2 (n=0,1,2, 3...) power, that is, at the 1st, 2nd, 4th, 8th, 16th... bits, and the rest of the bits can be filled with real data bits. If the information data is 1011, it can be known that the 1st, 2nd, 4th bits are correct Check bit, the 3rd, 5th, 6th and 7th bits are data bits

2^k>= n+k +1

n=4 is the data bit

k=1 does not hold

k=2 does not hold

k=3 established 8= 4+ 3+1

The calculation formula of each check code:

It is necessary to determine which information bits of each check code are in the check code, and divide the information bits (ie number) into binary representation, such as 7=4+2+1, by the fourth check bit r2 and the second bit The check bit r1 and the first check bit r0 are checked together. Similarly, the 6th data bit 6=4+2, the 5th data bit 5=4+1, and the 3rd data bit 3=2+1, as we know earlier, these 2 nth powers are all check digits, we can see , the 4th check digit checks the 7th, 6th, 5th, three-digit data, the 4th digit check digit r2 is equal to the XOR of the three-digit data, and the calculation principle of the 2nd and 1st digit check digit same.

r2 = I4 ^ I3 ^ I2 = 1 ^0 ^1= 0 — calculated by XORing the information bits

r1 = I4 ^ I3 ^ I1 = 1 ^ 0 ^ 1 = 0

r0 = I4 ^ I2 ^ I1 = 1 ^ 1 ^ 1 = 1

1 0 1 1 0 1 0 1

Error Detection and Correction Principles

After the receiver receives the Hamming code, it will XOR each check digit with its check digit, that is, perform the following three sets of operations:

r2 ^ I4 ^ I3 ^ I2

r1 ^ I4 ^ I3 ^ I1

r0 ^ I4 ^ I2 ^ I1

If it is an even check, then the result of the operation should be all 0, if it is an odd check, it should be all 1, which is correct. Error correction is finding the wrong bit and reversing that bit.

Guess you like

Origin blog.csdn.net/flysh05/article/details/124032715