CnPack Forum


 
Subject: crc的计算好像不对,请版主核实。
sxbug
新警察
Rank: 1



UID 446081
Digest Posts 0
Credits 28
Posts 9
点点分 28
Reading Access 10
Registered 2019-2-12
Status Offline
Post at 2023-3-8 00:01  Profile | Blog | P.M. 
crc的计算好像不对,请版主核实。

用的cnCRC32单元。
setlength(sendbyte, 15);    //sendbyte: TBytes;
  sendbyte[0]:=$FE;  sendbyte[1]:=$0D; sendbyte[2]:=$00;  sendbyte[3]:=$00;  sendbyte[4]:=$00;  sendbyte[5]:=$00;
  sendbyte[6]:=$03;  sendbyte[7]:=$00; sendbyte[8]:=$30;  sendbyte[9]:=$00;  sendbyte[10]:=$30;  sendbyte[11]:=$65;
  sendbyte[12]:=$2A; sendbyte[13]:=$31;  sendbyte[14]:=$34;
  mycrc:= CRC16Calc(0,sendbyte,15);     //FE 0D 00 00 00 00 03 00 30 00 30 65 2A 31 34
得到的结果是:70CD

但标准答案应该是:4BE6。
我也不知道错在哪里?请指教。
同时还想请问一下如何支持,其它格式的CRC计算呢?

谢谢
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6750
Posts 3551
点点分 6750
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2023-8-14 06:37  Profile | Blog | P.M. 
首先,CRC16Calc(0,sendbyte,15); 这句里的sendbyte应该是sendbyte[0],函数的注释中写了此参数不是地址。

其次,该函数的实现是CRC16 系列函数(CCITT),初始值 FFFF,结果异或值 0000,多项式为 x16+x12+x5+1
不知道你提到的标准答案的多项式和初始值是什么?
Top
 




All times are GMT++8, the time now is 2024-3-29 15:01

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008125 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP