CRC algorithm and its implementation

Source: Internet
Author: User
Tags zip

Absrtact: This paper first discusses the CRC's Algebra algorithm, then takes the common Crc-itu as an example, through the hardware circuit realization, has brought out the bit-type algorithm, finally emphatically introduced the byte type quick look-up table algorithm, has given the corresponding C language realization.

Keywords: CRC, FCS, generating polynomial, error retransmission

Introduction

CRC is all called cyclic redundancy check, the Chinese name is cyclic redundancy check. It is a kind of important linear block code, encoding and decoding method is simple, error detection and error correction ability, in the field of communication widely used to achieve error control. In fact, in addition to data communications, CRC in many other areas is also useful. For example, we read the file on the floppy disk, as well as the decompression of a zip file, occasionally encountered "bad CRC" error, which can be seen in the application of data storage.

The theory of error control is built on the basis of algebra theory. Here we look at the CRC algorithm and implementation, the principle can only be described by the introduction. If you need to further understand the principles of linear code, block code, cyclic code, error-correcting code, etc., you can read the relevant data.

The process of using CRC for error detection can be simply described as: in the sending end according to the K-bit binary sequence to be transmitted, a certain rule produces a check for the R-bit supervision code (CRC code), attached to the original information behind, constitute a new binary sequence number of total k+r bit, and then sent out. At the receiving end, the test is based on the rules followed between the information code and the CRC code to determine if there is an error in the transfer. This rule is called "generating polynomials" in the theory of error control.

The general algorithm of 1 generation mathematics

In algebraic coding theory, a code group is represented as a polynomial, and each code element in the code group is regarded as the coefficient of polynomial. For example, 1100101 is represented as

1 x6+1 x5+0 x4+0 x3+1 x2+0 x+1, or x6+x5+x2+1.

The original information polynomial before encoding is P (x), the maximum power of P (x) plus 1 equals k; the polynomial is g (x), the highest power of G (x) equals the R;CRC polynomial is R (x), and the encoded information polynomial with CRC is T (x).

Sender encoding Method: multiply P (x) by XR (that is, the corresponding binary sequence left R bit), and then divided by G (x), the resulting remainder is R (x). Represented by a formula as

T (x) =XRP (x) +r (x)

Receiver Decoding method: the T (x) is divided by G (x), if the remainder is 0, there is no error in the transmission, otherwise the transmission is incorrect.

For example, setting the information code to 1100, generating a polynomial of 1011, that is, p (x) =x3+x2,g (x) =x3+x+1, the procedure for calculating CRC is

xrP(x)   x3(x3+x2)   x6+x5          x
-------- = ---------- = -------- = (x3+x2+x) + --------
G(x)    x3+x+1   x3+x+1         x3+x+1

That is, R (x) =x. Note that g (x) is the highest power r=3, resulting in a CRC of 010.

If you use vertical division, the calculation process is

1110
------- 
1011 /1100000   (1100左移3位)
1011
----
1110
1011
-----
1010
1011
-----
0010
0000
----
010

Therefore, T (x) = (x6+x5) + (x) =x6+x5+x, i.e. 1100000+010=1100010

If the transmission is correct,

T(x)   x6+x5+x
------ = --------- = x3+x2+x,
G(x)   x3+x+1

No formula. Looking back at the vertical division above, if the divisor is 1100010, obviously in the third 1 o'clock of the business, can be done.

The above calculation process helps us to understand the CRC concept. But direct programming to achieve the above algorithm, not only cumbersome, inefficient. In fact, the CRC is not computed and validated directly in engineering.

Some of the standard CRC data are listed in the following table:

Name To generate the polynomial denoted type * Application examples
CRC-4 X4+x+1   ITU g.704
CRC-12 X12+x11+x3+x+1    
CRC-16 X16+x12+x2+1 1005 IBM SDLC
crc-itu** X16+x12+x5+1 1021 ISO HDLC, ITU X.25, v.34/v.41/v.42, Ppp-fcs
CRC-32 X32+x26+x23+...+x2+x+1 04c11db7 ZIP, RAR, IEEE Lan/fddi, IEEE 1394, Ppp-fcs
crc-32c X32+x28+x27+...+x8+x6+1 1edc6f41 Sctp

* 生成多项式的最高幂次项系数是固定的1,故在简记式中,将最高的1统一去掉了,如04C11DB7实际上是104C11DB7。
** 前称CRC-CCITT。ITU的前身是CCITT。

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.