国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee

 找回密碼
 注冊
搜索

CRC校驗源碼 VC++2012實現

[復制鏈接]
樓主
coolice 發表于 2020-5-3 16:29:19 | 只看該作者 |只看大圖 |倒序瀏覽 |閱讀模式
源程序如下: VC _計算CRC.rar (1.71 MB, 售價: 1 E幣)
CRC校驗源碼 VC++2012實現 1.png

  1. #include<iostream>
  2. #include<stdint.h>
  3. using namespace std;

  4. unsigned int CrcValueCalc(unsigned char *data,unsigned int length)
  5. {
  6.         unsigned int crcValue=0xffff;
  7.         int i;
  8.         while(length--)
  9.         {
  10.                 crcValue^=*data++;
  11.                 for(i=8-1;i>=0;i--)
  12.                 {
  13.                         if(crcValue & 0x0001)
  14.                         {
  15.                                 crcValue=(crcValue>>1)^0xa001;
  16.                         }
  17.                         else
  18.                         {
  19.                                 crcValue=crcValue>>1;
  20.                         }
  21.                 }
  22.         }
  23.         return crcValue;
  24.         //printf("%d%d",crcValue);
  25. }

  26. void main()
  27. {
  28.         uint8_t  data[]={0x00,0x03,0x10,0x04,0x00,0x01};
  29.         //uint8_t  data[]={0x00,0x03,0x0A,0x04,0x00,0x01};
  30.         //uint8_t  data[]={0x00,0x03,0x10,0x04,0x00,0x04};
  31.         //uint8_t  data[]={0x00,0x03,0x0A,0x04,0x00,0x04};
  32.         //uint8_t  data[]={0x01,0x03,0xF0,0x0A,0x00,0x02};
  33.         uint8_t a=CrcValueCalc(data,6);
  34.         //printf("%x",a);//輸出為ff
  35.     cout<<hex<<(int)a<<endl;
  36.         system("pause");
  37.         cout<<endl;
  38.         return;
  39. }
復制代碼

您需要登錄后才可以回帖 登錄 | 注冊

本版積分規則

手機版|小黑屋|ELEOK |網站地圖

GMT+8, 2026-5-26 07:17

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回復 返回頂部 返回列表