Skip to content

Instantly share code, notes, and snippets.

@hamrammi
Created July 4, 2017 08:09
Show Gist options
  • Save hamrammi/b4d873de255f30cd65bfdf2cd0498254 to your computer and use it in GitHub Desktop.
Save hamrammi/b4d873de255f30cd65bfdf2cd0498254 to your computer and use it in GitHub Desktop.
Convert number to hex representation
# coding: utf-8
def tohex(val, nbits=64):
return hex((val + (1 << nbits)) % (1 << nbits))
packet3 = (0x55, 0x01, 0xfe, 0x00, 0x00, 0x00)
print tohex(~sum(packet3)) # 0xfffffffffffffeabL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment