Skip to content

Instantly share code, notes, and snippets.

@avakar
Created January 2, 2012 16:23
Show Gist options
  • Save avakar/1551293 to your computer and use it in GitHub Desktop.
Save avakar/1551293 to your computer and use it in GitHub Desktop.
Converts a binary file to a C array
import sys
s = open(sys.argv[1], 'rb').read()
lines = []
while s:
bytes = ['0x%02x' % ord(ch) for ch in s[:16]]
lines.append(' ' + ', '.join(bytes) + ',' + '\n')
s = s[16:]
print ''.join(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment