迴圈校正碼

來源:互聯網
上載者:User

標籤:演算法

程式:

// X16+X12+X5+1 : 1,0001,0000,0010,0001 :0x11021unsigned char crcbuff [] = { 0x00,0x00,0x00,0x00,0x06,0x0d,0xd2,0xe3};unsigned int crc; // CRC 碼void main(void){unsigned char *ptr;crc = 0; // CRC 初值ptr = crcbuff; // 指向第一個 Byte 資料0x11021crc = crc16l(ptr,8);while(1);}/** *@brief  CRC16CTTTL的校正    *@note十六進位:0x11021 *二 進 制:0B10001000000100001 *多 項 式:X16+X12+X5+1  */// unsigned int crc; // CRC 碼unsigned int crc16l(unsigned char *ptr,unsigned char len) // ptr 為資料指標,len 為資料長度{unsigned char i;while(len--){for(i = 0x80; i!=0; i>>=1){if((crc & 0x8000) !=0 )//判斷第16位是不是 = 1 {crc <<= 1; crc  ^= 0x1021; // 1-1}else{crc <<= 1; // 1-2}if((*ptr & i) != 0)//判斷第16位是不是 = 1 {crc  ^= 0x1021; // 1-3(異或運算)}}ptr++;}return(crc);}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.