Last active
December 9, 2018 22:21
-
-
Save esutton/fb2e4a5a1bfb550003fab5bbe2f128f2 to your computer and use it in GitHub Desktop.
Print a string buffer in hex 16-bytes per row
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
# Debug dump bytes in hexadecimal format 16-bytes per row | |
# | |
# Example: | |
# 0000: d3 00 6a 3f 40 ee 06 7c a5 03 00 24 15 5c 27 40 | |
# 0016: df ef fa 0c a0 0e 10 4a 6f ff 74 10 68 7a b5 f0 | |
# | |
def debugDumpHexBytes(buffer, offsetStart, length): | |
print ('\n---- %d bytes --------------------') % (length) | |
i = 0 | |
row = 0 | |
while length > i: | |
rowData = '' | |
for col in range(0, 16): | |
if length <= i: | |
break | |
spacer = ' ' | |
if 7 == col: | |
spacer = ' ' | |
hexData = ('%02x') % (ord(buffer[i])) | |
rowData += hexData + spacer | |
i += 1 | |
print '%04d' % (row) + ': ' + rowData | |
row = row + 16 | |
print ('------------------------') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment