首页 > 编程知识 正文

手机端crc校验码计算小工具(crc校验码在线计算器)

时间:2023-05-04 18:59:11 阅读:73144 作者:4659

CRC循环冗馀校验码1介绍与2 CRC循环冗馀校验码计算机3 C和QT实现的CRC-16/MODBUS的码4进行校验,取8位(1字节)作为计算结果

1介绍循环冗馀校验码(CRC ),简称循环码。 是常用的具有检错、纠错能力的校验码,广泛用于早期通信。 循环冗馀校验码常用于外部存储器与计算机同步通信的数据检查。 奇偶校验码和汉明校验码都是以奇偶校验码为手段进行检错和纠错,但奇偶校验码不具备纠错能力。 另一方面,循环冗馀校验通过某种数学运算建立数据位与奇偶校验位的约束关系。 检查和检查比奇偶校验更可靠。 2 CRC循环冗馀校验码计算机

http://www.ip33.com/crc.html

3 C和QT实现的CRC-16/MODBUS代码# include ' main window.h ' # include qapplication # includeqbytearray # includeqdebug # include 未指定短整型CRC=0x ffff; if(len==0) { len=1; }while(len---- ) { crc ^=*ptr; for(I=0; i8; I ) if(CRC1 ) { crc=1; crc ^=0xA001; } else { crc=1; } } ptr; (返回) CRC; }intmain(intargv,char *argv[] ) qapplicationa ) argc,argv ); q字节阵列Ba; //0~18为检查数据,19~20为低奇偶校验位和高奇偶校验位ba.resize(21; ba[0]='x09 '; ba[1]='x03 '; ba[2]='x10 '; ba[3]='x00 '; ba[4]='x00 '; ba[5]='x00 '; ba[6]='x00 '; ba[7]='x00 '; ba[8]='x00 '; ba[9]='x00 '; ba[10]='x00 '; ba[11]='x00 '; ba[12]='x00 '; ba[13]='x00 '; ba[14]='x00 '; ba[15]='x00 '; ba[16]='x00 '; ba[17]='x00 '; ba[18]='x00 '; ba[19]='x06 '; ba[20]='x38 '; //将低奇偶校验位和高奇偶校验位置于位置QByteArray crc_real_tmp; CRC _ real _ tmp.append (ba [ ba.size (-1 ); CRC _ real _ tmp.append (ba [ ba.size (-2 ); bool ok; uint 16 _ tcrc _ real=CRC _ real _ tmp.to hex ().toint ) ok,16 ); uint8_t data [19]; memcpy(data,ba.mid ) 0,19 ); uint 16 _ tcrc _ RES=Modbus _ CRC 16 (data,19 ); if(CRC_RES==CRC_real ) { qDebug () ' true ); (假) q调试) ) '假); }返回0; }检查为4,以8位(1字节)作为计算结果,boolchargingpile 3360: _ verify sum (intindex ) { uint16_t sum=0; bool ok; for(intI=0; i=4; I ) { sum =_buffer[index i].toHex ().toint (确定,16 ); } uint16_t checksum=sum % 256; #1字节的uint 16 _ tcheck value=_ buffer [ index5].to hex ().toint ) ok,16 ); if(ans==checksum({returntrue; }返回假; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。