1.CRC校驗(yàn)原理1.1 CRC的基本概念:
本文引用地址:http://m.butianyuan.cn/article/201612/330194.htmCRC是英文Cyclical Redundancy Check的縮寫(xiě),翻譯成中文通常稱(chēng)作循環(huán)冗余校驗(yàn)或簡(jiǎn)稱(chēng)為CRC校驗(yàn)。它是數(shù)據(jù)傳輸領(lǐng)域中最常用的一種差錯(cuò)校驗(yàn)方法,其特點(diǎn)是傳輸數(shù)據(jù)和CRC校驗(yàn)值的長(zhǎng)度可以任意選定。在當(dāng)今手機(jī)、計(jì)算機(jī)和數(shù)碼產(chǎn)品普及的信息數(shù)字化時(shí)代,CRC校驗(yàn)無(wú)處不在。CRC分為多種標(biāo)準(zhǔn),例如:CRC -12碼通常用來(lái)傳送6-bit字符串。CRC-16及CRC-CCITT碼則用是來(lái)傳送8-bit字符,其中CRC-16多為美國(guó)采用,而CRC-CCITT多為歐洲國(guó)家所采用。而CRC-32碼大都被應(yīng)用在Point-to-Point的同步傳輸中。更多的CRC校驗(yàn)標(biāo)準(zhǔn)類(lèi)型參見(jiàn)附表:CRC校驗(yàn)標(biāo)準(zhǔn)類(lèi)型。
1.2 CRC校驗(yàn)的基本原理:
在代數(shù)編碼理論中,一個(gè)數(shù)值可以表示為一個(gè)多項(xiàng)式。例如:一個(gè)十進(jìn)制數(shù)值2892,可以用多項(xiàng)式表示為2x3+ 8x2+ 9x + 2(x=10)。同理,一個(gè)二進(jìn)制數(shù)值1010101對(duì)應(yīng)的多項(xiàng)式為x6+ x4+ x2+ 1(x=2)。
生成CRC碼的基本原理是:設(shè)被校驗(yàn)的數(shù)據(jù)為K位,校驗(yàn)碼為R位,碼字長(zhǎng)度為N(=K+R),則對(duì)于CRC碼集中的任一碼字,存在且僅存在一個(gè)R次多項(xiàng)式g(x),使得
V(x)=A(x)g(x)=xRm(x) + r(x);
其中: m(x)為被校驗(yàn)數(shù)據(jù)的K-1次多項(xiàng)式
r(x)為校驗(yàn)碼的R-1次多項(xiàng)式
g(x)稱(chēng)為生成多項(xiàng)式:g(x)=g0+ g1x1+ g2x2+ ... + g(R-1)x(R-1)+ gRxR
發(fā)送方通過(guò)指定的g(x)計(jì)算出CRC校驗(yàn)碼,接收方則通過(guò)該g(x)來(lái)驗(yàn)證收到的CRC校驗(yàn)碼。綜上所述,一個(gè)完整的CRC校驗(yàn)過(guò)程是:
發(fā)送方:根據(jù)要傳送的K位原始數(shù)據(jù)(二進(jìn)制碼序列),以標(biāo)準(zhǔn)指定的多項(xiàng)式計(jì)算出一個(gè)R位校驗(yàn)碼(CRC碼),附在原始數(shù)據(jù)后邊,構(gòu)成一個(gè)新的二進(jìn)制碼序列共K + R位,然后發(fā)送出去。
接收方:將接收到的數(shù)據(jù)除以與發(fā)送方相同的多項(xiàng)式值,如果能夠除盡,則正確,否則證明出錯(cuò)。還有另外一種處理,就是接收方用發(fā)送方相同的方法計(jì)算出接收到數(shù)據(jù)的CRC校驗(yàn)值,再與發(fā)送方發(fā)來(lái)的校驗(yàn)值比較,相同則正確,否則證明出錯(cuò)。
2. CRC校驗(yàn)碼的計(jì)算步驟:
例如:有一個(gè)要發(fā)送的7位二進(jìn)制數(shù)1011001;對(duì)應(yīng)的m(x)=x6+ x4+ x3+ 1。設(shè)CRC校驗(yàn)碼取4位并設(shè)g(x)=x4+ x + 1,則該多項(xiàng)式對(duì)應(yīng)的值是10011。根據(jù)CRC規(guī)則,為保證被除數(shù)夠除,首先需將要發(fā)送的數(shù)擴(kuò)大2R即24倍(左移4位),得到10110010000,對(duì)應(yīng)的xRm(x)=x10+ x8+ x7+ x4。
CRC校驗(yàn)碼的生成本質(zhì)其實(shí)就是采用模2除法取余數(shù),該除法的簡(jiǎn)捷計(jì)算就是將除數(shù)和被除數(shù)按位做異或(相同為0,不同為1。0^0=0; 0^1=1; 1^0=1; 1^1=0)運(yùn)算。需要注意的是,進(jìn)行異或運(yùn)算時(shí)除數(shù)必須和被除數(shù)最高有效位對(duì)齊。下面是將10110010000除以11001手工計(jì)算的演示,得到余數(shù)為1010,該值即是數(shù)據(jù)1011001的CRC校驗(yàn)值。
10110010000將1011001左移4位
10011多項(xiàng)式值與被除數(shù)最高有效位對(duì)齊
=00101010000第1次異或結(jié)果
10011多項(xiàng)式值與被除數(shù)最高有效位對(duì)齊
=00001100000第2次異或結(jié)果
10011多項(xiàng)式值與被除數(shù)最高有效位對(duì)齊
=00000101100第3次異或結(jié)果
10011多項(xiàng)式值與被除數(shù)最高有效位對(duì)齊
=00000001010第4次異或結(jié)果
為了簡(jiǎn)便計(jì)算機(jī)程序求解CRC,在實(shí)際應(yīng)用中通常把多項(xiàng)式值的最高位舍掉,并且將參加計(jì)算的數(shù)據(jù)高低位顛倒后再計(jì)算。前面的演算數(shù)據(jù)顛倒后的運(yùn)算情況如下:
00001001101
11001
00001010100
11001
00000110000
11001
00110100000
11001
01010000000
提請(qǐng)注意:只有真正讀懂以上手工演算的步驟和規(guī)律,才能理解下節(jié)內(nèi)容。
3. CRC校驗(yàn)的程序設(shè)計(jì)
下面以最常用的CRC-16-IBM校驗(yàn)標(biāo)準(zhǔn)為例來(lái)說(shuō)明CRC校驗(yàn)碼的生成過(guò)程。 因?yàn)镃RC-16碼由兩個(gè)字節(jié)構(gòu)成,所以首先要準(zhǔn)備一個(gè)16位的CRC寄存器,并將每一位都置1。具體的計(jì)算步驟為:
① 設(shè)置CRC寄存器,并給其賦值FFFFH。
② 將被校驗(yàn)數(shù)據(jù)的第一個(gè)字節(jié)(8Bit)與CRC寄存器的低8位進(jìn)行異或,結(jié)果存CRC寄存器。
③CRC寄存器的值向右移一位,最高位(MSB)補(bǔ)零,檢查移出的最低位(LSB)是否為1。
④ 如果LSB為0,重復(fù)第三步;若LSB為1,CRC寄存器與CRC16多項(xiàng)式值A(chǔ)001H相異或。
⑤ 重復(fù)第③與第④步,直到該字節(jié)的8次移位全部完成。
⑥ 如果被校驗(yàn)數(shù)據(jù)有多個(gè)字節(jié),則重復(fù)第②至第⑤步直到所有數(shù)據(jù)全部處理完。
⑦ 最終CRC寄存器的內(nèi)容即為CRC值。
3.1用查表法求CRC函數(shù)的程序
查表法省去了將被校驗(yàn)數(shù)據(jù)移位并與多項(xiàng)式異或計(jì)算的步驟,因此比計(jì)算法更快捷,但程序編碼量偏大。
3.1.1用VC編寫(xiě)的程序
unsigned short CRC16(puchMsg, usDataLen)
unsigned char * puchMsg ;
unsigned short usDataLen ;
{
unsigned char uchCRCHi = 0xFF ;
unsigned char uchCRCLo = 0xFF ;
unsigned uIndex ;
while (usDataLen--)
{
uIndex = uchCRCLo ^ * puchMsg++ ;
uchCRCLo = uchCRCHi ^ auchCRCLo [uIndex] ;
uchCRCHi = auchCRCHi [uIndex] ;
}
return (uchCRCLo << 8 | uchCRCHi) ;
}
static char auchCRCHi[] = {
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
0x43, 0x83, 0x41, 0x81, 0x80, 0x40 } ;
static unsigned char auchCRCLo[] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 } ;
3.1.2用VB編寫(xiě)的程序
Private Function CRC16(data() As Byte) As String
Dim CRC16Hi As Byte
Dim CRC16Lo As Byte
CRC16Hi = &HFF
CRC16Lo = &HFF
Dim i As Integer
Dim iIndex As Long
For i = 0 To UBound(data)
iIndex = CRC16Lo Xor data(i)
CRC16Lo = CRC16Hi Xor GetCRCLo(iIndex)’低位處理
CRC16Hi = GetCRCHi(iIndex)’高位處理
Next i
Dim ReturnData(1) As Byte
ReturnData(0) = CRC16Hi’CRC高位
ReturnData(1) = CRC16Lo’CRC低位
CRC16 = ReturnData
End Function
Function GetCRCHi(Ind As Long) As Byte’CRC高位字節(jié)值表
GetCRCHi = Choose(Ind + 1,_
&H00, &HC0, &HC1, &H01, &HC3, &H03, &H02, &HC2, &HC6, &H06,_
&H07, &HC7, &H05, &HC5, &HC4, &H04, &HCC, &H0C, &H0D, &HCD,_
&H0F, &HCF, &HCE, &H0E, &H0A, &HCA, &HCB, &H0B, &HC9, &H09,_
&H08, &HC8, &HD8, &H18, &H19, &HD9, &H1B, &HDB, &HDA, &H1A,_
&H1E, &HDE, &HDF, &H1F, &HDD, &H1D, &H1C, &HDC, &H14, &HD4,_
&HD5, &H15, &HD7, &H17, &H16, &HD6, &HD2, &H12, &H13, &HD3,_
&H11, &HD1, &HD0, &H10, &HF0, &H30, &H31, &HF1, &H33, &HF3,_
&HF2, &H32, &H36, &HF6, &HF7, &H37, &HF5, &H35, &H34, &HF4,_
&H3C, &HFC, &HFD, &H3D, &HFF, &H3F, &H3E, &HFE, &HFA, &H3A,_
&H3B, &HFB, &H39, &HF9, &HF8, &H38, &H28, &HE8, &HE9, &H29,_
&HEB, &H2B, &H2A, &HEA, &HEE, &H2E, &H2F, &HEF, &H2D, &HED,_
&HEC, &H2C, &HE4, &H24, &H25, &HE5, &H27, &HE7, &HE6, &H26,_
&H22, &HE2, &HE3, &H23, &HE1, &H21, &H20, &HE0, &HA0, &H60,_
&H61, &HA1, &H63, &HA3, &HA2, &H62, &H66, &HA6, &HA7, &H67,_
&HA5, &H65, &H64, &HA4, &H6C, &HAC, &HAD, &H6D, &HAF, &H6F,_
&H6E, &HAE, &HAA, &H6A, &H6B, &HAB, &H69, &HA9, &HA8, &H68,_
&H78, &HB8, &HB9, &H79, &HBB, &H7B, &H7A, &HBA, &HBE, &H7E,_
&H7F, &HBF, &H7D, &HBD, &HBC, &H7C, &HB4, &H74, &H75, &HB5,_
&H77, &HB7, &HB6, &H76, &H72, &HB2, &HB3, &H73, &HB1, &H71,_
&H70, &HB0, &H50, &H90, &H91, &H51, &H93, &H53, &H52, &H92,_
&H96, &H56, &H57, &H97, &H55, &H95, &H94, &H54, &H9C, &H5C,_
&H5D, &H9D, &H5F, &H9F, &H9E, &H5E, &H5A, &H9A, &H9B, &H5B,_
&H99, &H59, &H58, &H98, &H88, &H48, &H49, &H89, &H4B, &H8B,_
&H8A, &H4A, &H4E, &H8E, &H8F, &H4F, &H8D, &H4D, &H4C, &H8C,_
&H44, &H84, &H85, &H45, &H87, &H47, &H46, &H86, &H82, &H42,_
&H43, &H83, &H41, &H81, &H80, &H40)
End Function
Function GetCRCLo(Ind As Long) As Byte’CRC低位字節(jié)值表
GetCRCLo = Choose(Ind + 1,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41,_
&H00, &HC1, &H81, &H40, &H00, &HC1, &H81, &H40, &H01, &HC0,_
&H80, &H41, &H01, &HC0, &H80, &H41, &H00, &HC1, &H81, &H40,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H00, &HC1,_
&H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0, &H80, &H41,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H00, &HC1,_
&H81, &H40, &H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H00, &HC1, &H81, &H40,_
&H01, &HC0, &H80, &H41, &H01, &HC0, &H80, &H41, &H00, &HC1,_
&H81, &H40, &H01, &HC0, &H80, &H41, &H00, &HC1, &H81, &H40,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H00, &HC1, &H81, &H40,_
&H01, &HC0, &H80, &H41, &H00, &HC1, &H81, &H40, &H01, &HC0,_
&H80, &H41, &H01, &HC0, &H80, &H41, &H00, &HC1, &H81, &H40,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41,_
&H00, &HC1, &H81, &H40, &H00, &HC1, &H81, &H40, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41,_
&H01, &HC0, &H80, &H41, &H00, &HC1, &H81, &H40, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40, &H00, &HC1, &H81, &H40,_
&H01, &HC0, &H80, &H41, &H01, &HC0, &H80, &H41, &H00, &HC1,_
&H81, &H40, &H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41,_
&H00, &HC1, &H81, &H40, &H01, &HC0, &H80, &H41, &H01, &HC0,_
&H80, &H41, &H00, &HC1, &H81, &H40)
End Function
3.2用計(jì)算法求CRC函數(shù)的程序
計(jì)算法的優(yōu)點(diǎn)是程序編碼量小,雖然比查表法速度偏慢,但當(dāng)被校驗(yàn)的數(shù)據(jù)量不大時(shí)并不明顯。
3.2.1用VC編寫(xiě)的程序
unsigned short CRC16(unsigned char buf[], int n)
{
unsigned short crc = 0xffff ;
for(i = 0; i < n; i++)
{
crc ^ = buf[i] ;
for(b = 0; b < 8; b++)
{
bool f = crc & 1 ;
crc >> = 1 ;
if(f)
crc ^ = 0xa001 ;
}
}
return(crc) ;
}
3.2.2用VB編寫(xiě)的程序
Function CRC16(Data() As Byte, No As Integer, CRC16Lo As Byte, CRC16Hi As Byte) As String
Dim CL As Byte, CH As Byte, SaveLo As Byte, SaveHi As Byte
CRC16Hi = &HFF為16位CRC校驗(yàn)寄存器賦初始值FFFF
CRC16Lo = &HFF
CH = &HA0為16位CRC校驗(yàn)多項(xiàng)式賦初始值A(chǔ)001
CL = &H1
For i = 1 To No
CRC16Lo = CRC16Lo Xor Data(i - 1)每一個(gè)數(shù)據(jù)與CRC寄存器進(jìn)行異或
For j = 1 To 8
SaveHi = CRC16Hi
SaveLo = CRC16Lo
CRC16Hi = CRC16Hi 2高位右移一位
CRC16Lo = CRC16Lo 2低位右移一位
If ((SaveHi And &H1) = &H1) Then如果高位字節(jié)最右一位為1
CRC16Lo = CRC16Lo Or &H80則低位字節(jié)最左一位補(bǔ)1,否則自動(dòng)補(bǔ)0
End If
If ((SaveLo And &H1) = &H1) Then如低位字節(jié)最右一位為1,則與多項(xiàng)式值異或
CRC16Hi = CRC16Hi Xor CH
CRC16Lo = CRC16Lo Xor CL
End If
Next j
Next i
End Function
參考文獻(xiàn):
①GB/T 19582.1-2008《基于Modbus協(xié)議的工業(yè)自動(dòng)化網(wǎng)絡(luò)規(guī)范》
②《Modbus協(xié)議中文版》可在互聯(lián)網(wǎng)上下載
附表:CRC校驗(yàn)標(biāo)準(zhǔn)類(lèi)型
CRC校驗(yàn)名 | 多項(xiàng)式(標(biāo)準(zhǔn)引用名) | 對(duì)應(yīng)的16進(jìn)制值或反值注:已去掉最高位的1 |
CRC-1 | x + 1 (most hardware; also known as parity bit) | 01或01 (01) |
CRC-4-ITU | x4+x+ 1 (ITU G.704, p. 12) | 03或0C (09) |
CRC-5-ITU | x5+x4+x2+ 1 (ITU G.704, p. 9) | 15或15 (1A) |
CRC-5-USB | x5+x2+ 1 (USB token packets) | 05或14 (12) |
CRC-6-ITU | x6+x+ 1 (ITU G.704, p. 3) | 03或30 (21) |
CRC-7 | x7+x3+ 1 (telecom systems, MMC,SD) | 09或48 (44) |
CRC-8-ATM | x8+x2+x+ 1 (ATM HEC) | 07或E0 (83) |
CRC-8-CCITT | x8+x7+x3+x2+ 1 (1-Wire bus) | 8D或B1 (C6) |
CRC-8-Dallas/Maxim | x8+x5+x4+ 1 (1-Wire bus) | 31或8C (98) |
CRC-8 | x8+x7+x6+x4+x2+ 1 | D5或AB (EA) |
CRC-8-SAE J1850 | x8+x4+x3+x2+ 1 | 1D或B8 (8E) |
CRC-10 | x10+x9+x5+x4+x+ 1 | 233或331 (319) |
CRC-11 | x11+x9+x8+x7+x+ 1 (FlexRay) | 385或50E (5C2) |
CRC-12 | x12+x11+x3+x2+x+ 1 (telecom systems ) | 80F或F01 (C07) |
CRC-15-CAN | x15+x14+x10+x8+x7+x4+x3+ 1 | 4599或4CD1 (62CC) |
CRC-16-Fletcher | Not a CRC; see Fletchers checksum | Used in Adler-32 A & B CRCs |
CRC-16-CCITT | x16+x12+x5+ 1 (CRC-CCITT, G.hn PHY headers, 802.15.4, X.25, V.41, CDMA, Bluetooth, XMODEM, HDLC,PPP, IrDA, BACnet, MMC,SD) | 1021或8408 (8810) |
CRC-16-DNP | x16+x13+x12+x11+x10+x8+x6+x5+x2+ 1 (DNP, IEC 870, M-Bus) | 3D65或A6BC (9EB2) |
CRC-16-IBM | x16+x15+x2+ 1 (CRC-16, SDLC, USB, many others) | 8005或A001 (C002) |
CRC-24-Radix-64 | x24+x23+x18+x17+x14+x11+x10+x7+x6+x5+x4+x3+x+ 1 (FlexRay) | 864CFB或DF3261 (C3267D) |
CRC-30 | x30+x29+x21+x20+x15+x13+x12+x11+x8+x7+x6+x2+x+ 1 (CDMA) | 2030B9C7或38E74301 (30185CE3) |
CRC-32-Adler | Not a CRC; see Adler-32 | See Adler-32 |
CRC-32-IEEE 802.3 | x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+ 1 (V.42, MPEG-2, PNG [10], POSIX cksum) | 04C11DB7或EDB88320 (82608EDB) |
CRC-32C (Castagnoli) | x32+ x28+ x27+ x26+ x25+ x23+ x22+ x20+ x19+ x18+ x14+ x13+ x11+ x10+ x9+ x8+ x6+ 1 (G.hn payload) | 1EDC6F41或82F63B78 (8F6E37A0) |
CRC-32K (Koopman) | x32+x30+x29+x28+x26+x20+x19+x17+x16+x15+x11+x10+x7+x6+x4+x2+x+ 1 | 741B8CD7或EB31D82E (BA0DC66B) |
CRC-64-ISO | x64+x4+x3+ x + 1 (HDLC-ISO 3309) | 000000000000001B或D800000000000000 (800000000000000D) |
CRC-64-ECMA-182 | x64+ x62+ x57+ x55+ x54+ x53+ x52+ x47+ x46+ x45+ x40+ x39+ x38+ x37+ x35+ x33+ x32+ x31+ x29+ x27+ x24+ x23+ x22+ x21+ x19+ x17+ x13+ x12+ x10+ x9+ x7+ x4+ x + 1 (As described in ECMA-182 p.51) | 42F0E1EBA9EA3693或C96C5795D7870F42 (A17870F5D4F51B49) |
評(píng)論