
直接复制即可使用
用于安卓开发板ubuntu tcp上传用到的
参考文章crc16检验 python_Python CRC16校验算法_weixin_39628160的博客-CSDN博客def crc16(x, invert):a = 0xFFFFb = 0xA001for byte in x:a ^= ord(byte)for i in range(8):last = a % 2a >>= 1if last == 1:a ^= bs = hex(a).upper()return s[4:6]+s[2:4] if invert == True else s[2:4]+...https://blog.csdn.net/weixin_39628160/article/details/111956993
def crc16(x, invert):
a = 0xFFFF
b = 0xA001
for byte in x:
a = (a >> 8) ^ ord(byte)
for i in range(8):
last = a & 0x0001
a >>= 1
if last == 0x0001:
a ^= b
s = hex(a).upper()
return s[4:6] + s[2:4] if invert == True else s[2:4] + s[4:6]
#例子
print(crc16('QN=20220505153000155;ST=36;CN=2101;PW=123456;MN=00003;Flag=5;CP=&&DataTime=20220505153000;LFName=20220505_1530000_1530155.mp4&&', False))
print(len('QN=20220505153000155;ST=36;CN=2101;PW=123456;MN=00002;Flag=5;CP=&&DataTime=20220505153000;LFName=20220505_1530000_1530155.mp4&&'))欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)