以下是 16 进制表示,我把每一个 16 进制转换成 10 进制,然后进行累加,得到 2551
echo 2551&0xff;
转换成 16 进制是f7
5a 54 08 1f 01 01 61 00 50 53 0a 09 4e 01 64 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 50 53 0a 09 4f 03 64 00 00 00 00 00 00 00 50 53 0a 09 46 04 64 00 00 00 00 00 00 00 50 53 0a 0a 09 05 64 00 00 00 00 00 00 00 50 53 0a 0a 08 06 64 00 00 00 00 00 00 00 50 53 0a 09 34 07 64 00 00 00 00 00 00 00 50 53 0a 0a 0a 08 64 00 00 00 00 00 00 00
但是硬件那边传过来的求和校验是0x47
,是我哪里算错了吗
1
aa65535 2021-05-10 17:29:57 +08:00
明明加起来是 2631,不知道你为什么能得到 2551
|
2
SingeeKing 2021-05-10 17:40:15 +08:00
>>> sum([int(x, 16) for x in '''5a 54 08 1f 01 01 61 00 50 53 0a 09 4e 01 64 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 50 53 0a 09 4f 03 64 00 00 00 00 00 00 00 50 53 0a 09 46 04 64 00 00 00 00 00 00 00 50 53 0a 0a 09 05 64 00 00 00 00 00 00 00 50 53 0a 0a 08 06 64 00 00 00 00 00 00 00 50 53 0a 09 34 07 64 00 00 00 00 00 00 00 50 53 0a 0a 0a 08 64 00 00 00 00 00 00 00'''.strip().split()])
2631 |
3
takitooru 2021-05-11 00:00:38 +08:00
uint8_t test_list[]={0x5a,0x54,0x08,0x1f,0x01,0x01,0x61,0x00,0x50,0x53,0x0a,0x09,0x4e,0x01,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x09,0x4f,0x03,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x09,0x46,0x04,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x0a,0x09,0x05,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x0a,0x08,0x06,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x09,0x34,0x07,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x53,0x0a,0x0a,0x0a,0x08,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
int main(int argc,char *argv[]) { uint8_t rst = 0; for(int i=0;i<sizeof(test_list);i++) { rst += test_list[i]; } printf("%d 0x%02x",rst,rst); } gcc .\test6_sig.c -m32 .\a.exe -> 71 0x47 |
4
cs5117155 OP 谢谢大家,原来我自已程序过滤了一个字节,导致结果错误了,2631 是对的
|