登录  注册 退出 English
鼎恩光彩{www.deanled.cn}
400-886-2386
  1. 首页 > 服务支持 > 二次开发

C++语言CRC16校验算法

C++语言CRC16校验算法:----------------------------------------------------------#includeclass CRC...
作者:小编 上传时间:2019-03-18 浏览量:910
文件下载列表 :
详细介绍

C++语言CRC16校验算法:

----------------------------------------------------------

#include<iostream.h>

class CRC16

{

public :

int crc16 (unsigned char * data,int size)

{

unsigned char data_t ;

int crc,i,j;

crc = i = j = 0;

if (data == NULL)

{

return 0;

}

for (j=0;j<size;j++)

{

data_t = data [j];

crc = (data_t ^ crc);

for (i=0;i<8;i++)

{

if ( (crc&0x1)==1)

{

crc = (crc >> 1) ^ 0xA001;

}

else

{

crc >>= 1;

}

}

}

return crc;

}

};

int main ()

{

unsigned char array [] = {0x88,0x77,0xFF,0x9A};

int checkValue;

CRC16 test;

checkValue = test.crc16 (array,sizeof (array));

cout<<"CRC16  :"<<hex<< ( (checkValue >> 8) & 0xff);

cout<<" "<<hex<< (checkValue & 0xff)<<endl<<endl;

return 0;

}


------------------------------------------------------------------------

image.png




随便看看
18922864126
18922864126
已为您复制好微信号,点击进入微信