Created
August 25, 2017 06:37
-
-
Save dev-zzo/de29434740d6c6642ccff90061fffd87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def hexdump(data): | |
"""Pretty print a hex dump of data, similar to xxd""" | |
lines = [] | |
offset = 0 | |
while offset < len(data): | |
piece = data[offset:offset + 16] | |
bytes = ''.join([('%02x ' % ord(x)) for x in piece]) | |
chars = ''.join([(x if 0x20 < ord(x) < 0x7f else '.') for x in piece]) | |
lines.append('%04x %-24s %-24s %-16s' % (offset, bytes[:24], bytes[24:], chars)) | |
offset += len(piece) | |
return "\n".join(lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment