Last active
December 10, 2016 11:59
-
-
Save tmthydvnprt/db557be31fcb28b6b784a3d698f377be to your computer and use it in GitHub Desktop.
ASCII <-> Binary <-> Hex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def string2bitstring(s=''): | |
| return ''.join([bin(ord(x))[2:].zfill(8) for x in s]) | |
| def bitstring2string(b=None): | |
| return ''.join([chr(int(x, 2)) for x in [b[i:i+8] for i in xrange(0, len(b), 8)]]) | |
| def string2bitlist(s=''): | |
| return [bin(ord(x))[2:].zfill(8) for x in s] | |
| def bitlist2string(b=None): | |
| return ''.join([chr(int(x, 2)) for x in b]) | |
| def string2hexstring(s=''): | |
| return ''.join([hex(ord(x))[2:].zfill(2) for x in s]) | |
| def string2hexlist(s=''): | |
| return [hex(ord(x))[2:].zfill(2) for x in s] | |
| def hexstring2string(b=None): | |
| return ''.join([chr(int(x, 16)) for x in [b[i:i+2] for i in xrange(0, len(b), 2)]]) | |
| def hexlist2string(b=None): | |
| return ''.join([chr(int(x, 16)) for x in b]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment