Skip to content

Instantly share code, notes, and snippets.

@klette
Created June 30, 2009 13:18
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 klette/138149 to your computer and use it in GitHub Desktop.
Save klette/138149 to your computer and use it in GitHub Desktop.
def unpack_string(octet_string):
ret = []
for hex in octet_string.split(' '):
octets = struct.unpack('2c', hex)
for octet in octets:
b_repr = bin(int(octet, 16)).replace('b','')
ret.append( b_repr.ljust(4, '0'))
return [b[0]+1 for b in enumerate([a for a in "".join(ret)]) if b[1] == '1']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment