Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Last active June 17, 2023 02:20
Show Gist options
  • Save skratchdot/7868a3d0880cbc5ea44c7f1bfcebff85 to your computer and use it in GitHub Desktop.
Save skratchdot/7868a3d0880cbc5ea44c7f1bfcebff85 to your computer and use it in GitHub Desktop.
hexdump tools for pretty printing strings/files as hex dumps

hexdump

here are a few tools to "pretty print" a string/file as a hex dump

bash tools:

node/javascript:

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();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment