How to Create a Hexdump of a File or String of Text

Hexdumps support program debugging and reverse compilation

A hex dump is a hexadecimal view of data. Use hexadecimal when you're debugging a program or to reverse engineer a program.

For example, many file formats employ specific hex characters to denote their type. When you try to read a file but it doesn't load correctly, it might be that the file isn't in the format you are expecting. A hex dump helps with troubleshooting. Likewise, to deconstruct how a program works without the source code, look at the hex dump to evaluate its performance.

What Is Hexadecimal?

Computers think in binary. Every character, number, and symbol is referenced by a binary values—something called base 2 arithmetic, using zeroes and ones. Humans think in decimal, or base 10 arithmetic that relies on the numerals zero through nine. In hexadecimal—or base 16 arithmetic—computations use 16 units represented by the figures zero through nine plus the letters A through F.

How to Create a Hex Dump Using Linux

hex dump

To create a hex dump using Linux, use the hexdump command.

To display a file as hex to the standard output, run the following command:

hexdump filename

For example:

hexdump touch.svg

The default output displays the line number in hexadecimal format through eight sets of four hexadecimal values per line.

Supply different switches to change the default output. For example, specifying the -b switch produces an eight-digit offset followed by 16 three-column, zero-filled bytes of input data in octal format—a view called a one-byte octal display.

hexdump -b touch.svg

With this switch, the display changes to look something like this:

00000000 211 120 116 107 015 012 032 012 000 000 000 015 111 110 104 122

Use the -c switch to see the file in a one-bit display:

hexdump -c hexdump.svg

The command with this switch displays the offset but this time in the form of 16 space-separated, three-column, space-filled characters of input data per line:

hexdump with -c option

This command supports several other output formats. Run the command man hexdump to view the manpage entry for this useful tool.