Skip to content

Instantly share code, notes, and snippets.

@plainas
Created December 16, 2018 23:01
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 plainas/f7fa9af721ac84c56c3727115243f207 to your computer and use it in GitHub Desktop.
Save plainas/f7fa9af721ac84c56c3727115243f207 to your computer and use it in GitHub Desktop.
hexstring to binstring
def hex2binstr(bstr):
t = {
"0" : '0000',
"1" : '0001',
"2" : '0010',
"3" : '0011',
"4" : '0100',
"5" : '0101',
"6" : '0110',
"7" : '0111',
"8" : '1000',
"9" : '1001',
"a" : '1010',
"b" : '1011',
"c" : '1100',
"d" : '1101',
"e" : '1110',
"f" : '1111',
}
o = ""
for b in bstr:
o = o + t[b]
return o
print(hex2binstr("d4f3"))
print(hex2binstr("caf3"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment