Last active
December 20, 2015 03:29
-
-
Save samalba/6064030 to your computer and use it in GitHub Desktop.
Convert a binary file into an array of bytes which can be inserted in a code
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
#!/usr/bin/env python | |
import sys | |
if __name__ == '__main__': | |
fname = sys.argv[1] | |
with open(fname) as f: | |
print '[' | |
while True: | |
b = f.read(14) | |
if not b: | |
break | |
print ' '.join(['0x{0:02x},'.format(ord(i)) for i in b]) | |
print ']' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment