Created
December 5, 2014 13:54
-
-
Save TimSC/bed3b068d241f4abe167 to your computer and use it in GitHub Desktop.
Convert binary data to hex representation and back
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
import string | |
def BinToHex(a): | |
return "".join(["%02x" % ord(ch) for ch in a]) | |
def HexToBin(a): | |
out = [] | |
for i in range(0, len(a), 2): | |
twoChrs = a[i:i+2] | |
v = string.atoi(twoChrs, 16) | |
out.append(chr(v)) | |
return "".join(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment