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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退