May-23-2017, 09:50 AM
Pages: 1 2
May-23-2017, 12:09 PM
FINALLY!!!! WITH THAT CODE:
Where I'm wrong now?
def crc16(data, bits=8): crc = 0xFFFF for op, code in zip(data[0::2], data[1::2]): crc = crc ^ int(op+code, 16) for bit in range(0, bits): if (crc&0x0001) == 0x0001: crc = ((crc >> 1) ^ 0xA001) else: crc = crc >> 1 msb = hex(crc >> 8) lsb = hex(crc & 0x00FF) return lsb + msbThe result is:
>>> crc16('11010003000C') '0xce0x9f'But I need to "clean" the result and must be "0E9F"
Where I'm wrong now?
May-23-2017, 12:12 PM
0E9F or CE9F as you claimed in previous posts?
May-23-2017, 12:14 PM
(May-23-2017, 12:12 PM)buran Wrote: [ -> ]0E9F or CE9F as you claimed in previous posts?
I have correct the code now.
Result must be CE9F without "0x"
May-23-2017, 12:31 PM
def crc16(data, bits=8): crc = 0xFFFF for op, code in zip(data[0::2], data[1::2]): crc = crc ^ int(op+code, 16) for bit in range(0, bits): if (crc&0x0001) == 0x0001: crc = ((crc >> 1) ^ 0xA001) else: crc = crc >> 1 msb = crc >> 8 lsb = crc & 0x00FF return '{:X}{:X}'.format(lsb, msb) print crc16('11010003000C')
May-23-2017, 12:59 PM
You are my hero! Thanks a lot!
Pages: 1 2