Created
May 22, 2017 16:23
-
-
Save rrooij/d4f66358cbeaf65789830bf0868b6e9a to your computer and use it in GitHub Desktop.
Checksum Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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