python 撰寫crc校驗 x16+x15+x2+1 我要校驗11,生成0x0066
用下面演算法得到的是0x0707
def crc16(x, invert):
a = 0x0000
b = 0x8005
for byte in x:
a ^= ord(byte)
for i in range(8):
last = a % 2
a >>= 1
if last == 1:
a ^= b
s = hex(a).upper()
return s[4:6] + s[2:4] if invert == True else s[2:4] + s[4:6]
bb=crc16("11",False)
print(bb)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/46745.html
