Skip to content

Instantly share code, notes, and snippets.

@fbstj
Created July 2, 2013 09:37
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 fbstj/5907978 to your computer and use it in GitHub Desktop.
Save fbstj/5907978 to your computer and use it in GitHub Desktop.
def signed(chars, index = 0, length = 16):
"""convert a `length/4` character hex string into a signed `length`-bit number"""
v = int(chars[index:][:(length / 4)], 16)
return v if v < (1 << (length - 1)) else v - (1 << length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment