Skip to content

Instantly share code, notes, and snippets.

@cessor
Last active September 6, 2021 15:15
Show Gist options
  • Save cessor/96ca02de530fac17dca573d496056081 to your computer and use it in GitHub Desktop.
Save cessor/96ca02de530fac17dca573d496056081 to your computer and use it in GitHub Desktop.
hexshow.py
with open('png.png', 'rb') as file:
content = file.read()
for i in range(0 , len(content), 16):
# row offset
print(f'{i:08X}', end=' ')
# byte display
row = content[i:i + 16]
for byte in row:
print(f'{byte:02X} ', end='')
# padding
if len(row) < 16:
print('', ' '.join([' '] * (16 - len(row))), end='')
# char display
print('', ''.join([
chr(byte)
if 0x20 <= byte <= 0x7f
else '.'
for byte in row
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment