Skip to content

Instantly share code, notes, and snippets.

@rrooij
Created May 22, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrooij/d4f66358cbeaf65789830bf0868b6e9a to your computer and use it in GitHub Desktop.
Save rrooij/d4f66358cbeaf65789830bf0868b6e9a to your computer and use it in GitHub Desktop.
Checksum Python
def sum16_checksum(bytes, big=True):
sum = 0
count_to = len(bytes)
count = 0
while count_to > count:
value = bytes[count + 1] + bytes[count]
sum = sum + value
count = count + 2
if big:
sum = sum >> 8 | (sum << 8 & 0xff00) # Swap bytes for big endian
return sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment