Skip to content

Instantly share code, notes, and snippets.

@samalba
Last active December 20, 2015 03:29
Show Gist options
  • Save samalba/6064030 to your computer and use it in GitHub Desktop.
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
#!/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