breezeair 2019-12-25 09:43 采纳率: 33.3%
浏览 179

各位大佬,这段C代码小弟实在看不懂,在线求助谢谢

char crcCACheck(char *p, char len) 
{     
    short t_short =0;     
    for(int i=0; i<len; i++)    
    {         
        t_short +=*p++; 
        t_short += t_short >>8;         
        t_short &=0xFF;     
    }          
    return 0xFF - t_short; 
}    

校验的数据如下:

 Len  PhyId  prim     appId  L/H   D1  D2  D3   D4 CRC    
08    8e     00        00    2f   18   ff  e3   1b  df

Len byte the value is the number of bytes in the frame, Len/CRC bytes are not included CRC byte this byte is summed after Len field to the byte in front of CRC with carry should be 0xFF. Every frame has a CRC byte, this byte is calculated with an add-with-carry method, bytes in frame are added from Len field, together with the carry value.
**Every frame has a Len byte, which calculate the frame bytes, does not include Len/CRC byte **
这是一段C代码(应该是C吧),写的是对crc校验,我想改写成python,一时无能为力,向各位大佬求助,十分感谢。

  • 写回答

1条回答 默认 最新

  • bobhuang 2019-12-25 11:13
    关注
    a = 'Hello'
    b = 0
    for x in a:
      b += ord(x)
        b += b>>8
        b = b & 0xff
    c = 0xff - b
    print(c)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题