CRC校驗VC2012實現
0.png (43.31 KB, 下載次數: 62)
下載附件
2017-11-3 17:29 上傳
源程序如下:
- #include<iostream>
- #include<stdint.h>
- using namespace std;
- unsigned int CrcValueCalc(unsigned char *data,unsigned int length)
- {
- unsigned int crcValue=0xffff;
- int i;
- while(length--)
- {
- crcValue^=*data++;
- for(i=8-1;i>=0;i--)
- {
- if(crcValue & 0x0001)
- {
- crcValue=(crcValue>>1)^0xa001;
- }
- else
- {
- crcValue=crcValue>>1;
- }
- }
- }
- return crcValue;
- //printf("%d%d",crcValue);
- }
- void main()
- {
- uint8_t data[]={0x00,0x03,0x10,0x04,0x00,0x01};
- //uint8_t data[]={0x00,0x03,0x0A,0x04,0x00,0x01};
- //uint8_t data[]={0x00,0x03,0x10,0x04,0x00,0x04};
- //uint8_t data[]={0x00,0x03,0x0A,0x04,0x00,0x04};
- //uint8_t data[]={0x01,0x03,0xF0,0x0A,0x00,0x02};
- uint8_t a=CrcValueCalc(data,6);
- //printf("%x",a);//輸出為ff
- cout<<hex<<(int)a<<endl;
- system("pause");
- cout<<endl;
- return;
- }
復制代碼
所有資料51hei提供下載:
計算CRC.rar
(1.71 MB, 下載次數: 13)
2017-11-3 14:54 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|