Skip to content

Instantly share code, notes, and snippets.

@teodor-stoenescu
Created August 18, 2017 20:54
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 teodor-stoenescu/9dcf8160da447f8a30b0f14327e6c5c6 to your computer and use it in GitHub Desktop.
Save teodor-stoenescu/9dcf8160da447f8a30b0f14327e6c5c6 to your computer and use it in GitHub Desktop.
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