add hexdump util

This commit is contained in:
2025-07-30 19:41:10 -05:00
parent ac59280ee2
commit dc0f6cd0e2

15
hexdump.py Normal file
View File

@@ -0,0 +1,15 @@
# https://stackoverflow.com/a/79038702
def hexdump(data: bytes):
def to_printable_ascii(byte):
return chr(byte) if 32 <= byte <= 126 else "."
offset = 0
while offset < len(data):
chunk = data[offset : offset + 16]
hex_values = " ".join(f"{byte:02x}" for byte in chunk)
ascii_values = "".join(to_printable_ascii(byte) for byte in chunk)
print(f"{offset:08x} {hex_values:<48} |{ascii_values}|")
offset += 16