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

Hexdumps support program debugging and reverse compilation

Hexdump shown on the Windows command shell


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 have specific hex characters to denote their type. If you are trying to read a file using a program and for some reason, it isn't loading correctly, it might be that the file isn't in the format you are expecting.

If you want to see how a program works and you don't have the source code or piece of software which reverse engineers the code, you can look at the hex dump to try and work out what is happening.

What Is Hexadecimal?

Computers think in binary. Every character, number, and symbol is referenced by a binary or multiple 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 terminal (standard output) run the following command:

hexdump filename

For example

hexdump touch.svg

The default output will display the line number (in hexadecimal format) and then 8 sets of 4 hexadecimal values per line.

Supply different switches to change the default output. For example, specifying the -b switch will produce an eight-digit offset followed by 16 three-column, zero-filled bytes of input data in octal format.

hexdump -b touch.svg

Therefore the above example will now be represented as follows:

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

The above format is known as one-byte octal display.

Another way to view the file is in one-byte character display using the -c switch.

hexdump -c hexdump.svg

This again displays the offset but this time followed by 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.