Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Created October 29, 2015 06:40
Show Gist options
  • Save yohhoy/fbbc04721ad56f08693f to your computer and use it in GitHub Desktop.
Save yohhoy/fbbc04721ad56f08693f to your computer and use it in GitHub Desktop.
convert from hex text to binary
#!/usr/bin/env python3
import sys
import struct
if len(sys.argv) != 3:
print("Usage: {} <source> <target>".format(sys.argv[0]))
quit()
with open(sys.argv[1]) as f:
hex = f.read()
with open(sys.argv[2], 'wb') as f:
for h in hex.split():
f.write(struct.pack('B', int(h, 16)))
print(f.tell())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment