Created
July 5, 2011 18:25
-
-
Save jinie/1065494 to your computer and use it in GitHub Desktop.
Read binary file in python and print hex output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys,getopt | |
filename = None | |
blocksize = 1024 | |
opts,args = getopt.getopt(sys.argv[1:],'f:b:') | |
for o,a in opts: | |
if o == '-f': | |
filename = a | |
if o == '-b': | |
blocksize = a | |
offset = 0 | |
with open(filename,"rb") as f: | |
block = f.read(blocksize) | |
str = "" | |
for ch in block: | |
str += hex(ord(ch))+" " | |
print str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment