here are a few tools to "pretty print" a string/file as a hex dump
- hexdump:
https://man7.org/linux/man-pages/man1/hexdump.1.html - od:
https://man7.org/linux/man-pages/man1/od.1.html - hexyl:
https://github.com/sharkdp/hexyl - hexutils:
https://github.com/denysvitali/hexutils - hexcurse:
https://github.com/LonnyGomes/hexcurse
Here is a simple javascript function that converts a buffer to a hexdump string:
const hexFormat = (buffer) => {
const arr = [];
for (let i = 0; i < buffer.byteLength; i++) {
if (i % 16 === 0) {
arr.push(`\n0x${i.toString(16).padStart(10, 0)}`);
}
arr.push(' ', buffer.readUInt8(i).toString(16).padStart(2, 0));
}
return arr.join('').trim();
};