我会说这段代码会提供三次相同的输出,但它不会:
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!
请解释!