我要說的是,這個代碼將提供相同的輸出3次,但它並不:爲什麼python的這個CRC16計算有不同?
import crcmod
#create CRC16 calculator
crc16 = crcmod.predefined.mkCrcFun('crc-16')
#wait for user input
#hstr = raw_input("enter hex commands, space separated: ")
hstr = '81 12 C0 00 01 05'
hex_series = hstr.replace(' ', '\\x')
hex_series_caps = hstr.capitalize().replace(' ', '\\x') #why is there difference?
print hex(crc16(hex_series)) # gives 0xd795 incorrect! + how can there be a 9???
print hex(crc16(hex_series_caps)) # gives 0x37b4 incorrect!
print hex(crc16('\x81\x12\xC0\x00\x01\x05')) # gives 0x815b correct!
請解釋!
好想起了'b16decode' + 1 –