Skip to content

Instantly share code, notes, and snippets.

@fbstj fbstj/signed.py
Created Jul 2, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.