找回密码
 注册

QQ登录

只需一步,快速开始

搜索

CRC校验源码 VC++2012实现

[复制链接]
coolice 发表于 2020-5-3 16:29:19 | 显示全部楼层 |阅读模式
源程序如下: VC _计算CRC.rar (1.71 MB, 售价: 1 E币)
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. }
复制代码

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-3-29 14:56

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表