Problem
I am writing code for an embedded device. A lot of solutions out there for CRC-CCITT 16-bit calculations require libraries.
Given that u
Here's a function that I use:
def crc16_ccitt(crc, data): msb = crc >> 8 lsb = crc & 255 for c in data: x = ord(c) ^ msb x ^= (x >> 4) msb = (lsb ^ (x >> 3) ^ (x << 4)) & 255 lsb = (x ^ (x << 5)) & 255 return (msb << 8) + lsb