Skip to content

Instantly share code, notes, and snippets.

@kayru
Created December 8, 2011 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayru/1448896 to your computer and use it in GitHub Desktop.
Save kayru/1448896 to your computer and use it in GitHub Desktop.
Create array from binary file
import sys
import textwrap
s=open(sys.argv[1], 'rb').read().encode("hex").upper()
t=",".join(["0x"+x+y for (x,y) in zip(s[0::2], s[1::2])])
print "const unsigned char data[] = {\n\t%s\n};"%" \n\t".join(textwrap.wrap(t,80))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment