Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python tool to convert binary files to arrays of bytes (useful for loading into Arduino progmem)
from __future__ import with_statement
import sys
with open(sys.argv[1], "rb") as f:
b = f.read(1)
t = 0
while b:
sys.stdout.write("{0:#0{1}x}, ".format(ord(b), 4))
t += 1
if 8 == t :
sys.stdout.write("\n")
t = 0
b = f.read(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.