Skip to content

Instantly share code, notes, and snippets.

@jonahbardos
Last active July 3, 2021 14:33
Show Gist options
  • Save jonahbardos/bb36e3734eccb5a1882507c6173d0aa5 to your computer and use it in GitHub Desktop.
Save jonahbardos/bb36e3734eccb5a1882507c6173d0aa5 to your computer and use it in GitHub Desktop.
Implementation of crc16 (CRC-16-CCITT) in Python with Modbus Protocol Error Detection
def crc16_generator(data):
'''
CRC-16-CCITT Algorithm
'''
data = bytearray(data)
crc = 0xFFFF
for b in data:
crc ^= b
for _ in range(0, 8):
bcarry = crc & 0x0001
crc >>= 1
if bcarry:
crc ^= 0xa001
return crc
@jonahbardos
Copy link
Author

For additional information see Repository:

Python-CRC16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment