Last active
September 6, 2021 15:15
-
-
Save cessor/96ca02de530fac17dca573d496056081 to your computer and use it in GitHub Desktop.
hexshow.py
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
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