(From http://www.equn.com/forum/viewthread.php? Tid = 5470 & SID = 3 rrqvomr)
The basic idea of CRC verification code is to use the linear encoding theory to generate a verification supervised code (both CRC code) at the sender Based on the K-bit binary code sequence to be transmitted with certain rules) r bit, which is attached to the back of the information to form a new binary code sequence number (K + r) bit, and finally sent out. At the receiving end, the system checks the rules followed by the Information Code and CRC code to determine whether an error occurs during transmission.
In the field of data storage and data communication, CRC is everywhere: the famous communication protocol X.25's FCS (frame check error sequence) uses CRC. CRC32 is used by CCITT, ARJ, LHA, and other compression tools, crc16 is used for disk drive reading and writing, and CRC is also used for common image storage formats, such as GIF and Tiff.
The essence of CRC is the remainder of the Modulo-2 Division. The type of CRC varies depending on the divisor used. Generally, the division of CRC is expressed by generating polynomials. The polynomials of the most common CRC codes are crc16 and crc32.
Taking crc16 as an example, a 16-bit CRC code generates a rule that first shifts the number of binary sequences to be sent by 16 bits (both multiplied by 2 ^ 16) and then divided by a polynomial, the remainder is a CRC code, as shown in the following formula. k (x) indicates the number of N-bit binary sequences, g (x) is a polynomial, and Q (x) is an integer, R (x) is the remainder (both CRC code ).
K (x)> 16 = g (x) Q (x) + R (X)
The addition and subtraction algorithm of mod 2 is used to calculate the CRC code, which is not to add bitwise addition and subtraction of bitwise AND borrow. This addition and subtraction operation is actually an exclusive or logical operation. addition and subtraction are equivalent, multiplication and division operations are the same as ordinary algebraic multiplication and division operations. The polynomial of CRC code generation is as follows, where CRC-16 and CRC-CCITT generate 16-bit CRC code, while CRC-32 produces 32-bit CRC code
The receiver divides the number of received binary sequences (including the Information Code and CRC Code) by the polynomial. If the remainder is 0, no error occurs during transmission. Otherwise, the transmission is incorrect, I will not describe its principles here. When the CRC code is calculated using software, the receiver can calculate the CRC code for the received information code, and compare the result with whether the received CRC code is the same.
In frame verification sequence of HDLc, crc16 is a CCITT-16 used in the frame verification sequence of the advanced data link control procedure recommended by CCITT, its generated polynomials are g (x) = x16 + X12 + X5 + 1, the polynomial generated for the CRC-32 is g (x) = x32 + X26 + x23 + x22 + x16 + X11 + x10 + x16 + X8 + X7 + X5 + X4 + X2 + x + 1