pyapple2disk/src/apple2disk/utils.py
kris b4ea155b24 Add a utils.HexDump library
Be a bit more robust about dealing with data corruption
2017-04-16 22:56:04 +01:00

18 lines
444 B
Python

import string
PRINTABLE = set(string.letters + string.digits + string.punctuation + ' ')
def HexDump(data):
line = []
for idx, b in enumerate(data):
if idx % 8 == 0:
print '$%02x: ' % idx,
print "%02x" % ord(b),
if b in PRINTABLE:
line.append(b)
else:
line.append('.')
if (idx + 1) % 8 == 0:
print " %s" % ''.join(line)
line = []