Tuesday Tool: Hex editors and hex dumps

Text files are easy to view using a program like TextEdit. Programmers often have to deal with binary files, and deal with them in some reasonable format. Here are several useful tools for binary files.


As an example, if I wanted to view a png file in hexadecimal, I could use hexdump from the command line:

hexdump myfile.png

0000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52
0000010 00 00 00 0a 00 00 00 03 08 06 00 00 00 aa 3d 9e
0000020 75 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b
0000030 13 01 00 9a 9c 18 00 00 00 04 67 41 4d 41 00 00

You could then whip out a handy hex to ascii chart, or you could use the command line tool “od”. This tool allows to specify what format you want the output in, for instance in ascii bytes. This makes it very clear that the first four bytes are the magic header for PNG files.

od -a HRidges.png

0000000   89   P   N   G  cr  nl sub  nl nul nul nul  cr   I   H   D   R
0000020  nul nul nul  nl nul nul nul etx  bs ack nul nul nul   ?   =  9e

You might find want to also have a hex editor so that you can edit the files as well. I tend to use 0xED.app. You can find it at Suavetech. An alternative to 0XED is HexFiend, which is also available in source code form.

This entry was posted in Tools. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.
  • iChat Status