So how does hex work, what is a hex editor and why might you need to use one on your PC?
What Is Hex?
The number system that humans use to count is called decimal, the numbers from 0 to 9. Decimal was invented by the Persians about 6000 years ago.
Fast forward to 1679. The binary number system made up of 0s and 1s was.
Finally in the 1950s or 1960s IBM formalized the Hexadecimal number system, which is a short way to represent binary data. Instead of using digits 0-9, hexadecimal uses digits from 0 to F. Counting from 0 to 31 (converting from decimal to hexadecimal):
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
Once you reach the end of the numeric “digits”, you simply increase the number to the left by one, just like you do with the decimal counting system.
Now that we have the basics of hexadecimal out of the way, let’s move on to some hex editors.
Hex editors differ from a regular text editors in a number of ways. The basis of a hex editor is that they display the raw contents of the file. No encoding or translation into text – just the raw machine code. The second is that line numbers instead of being based on “lines” are an offset address from the beginning of the file.
My favorite hex editor is PSPad. PSPad, in addition to being a great text and code editor, offers the “Open in HEX Editor …” option which will launch the special editing mode.
Once you are in this mode, you can see the location and hexadecimal values of each bit of the file. You have two choices for editing the file – you can either edit the hexadecimal values by location, or on the right side you have the alphanumeric representation of that value which you can also edit.
XVI32 is also a very capable hex editor. As with PSPad you can edit the hex values directly or the character representation.
It also has some advanced hex editing tools such as an address calculator for checking offsets and some other hex-specific options which can help you get around a hex file if you know what you are doing.
What Can You Do With A Hex Editor?
Now that you know what a hex value is, and how you can open and edit them, why would you want to do that exactly?
Find Out A File Type
Every once in a while you might come across a file that you just can’t seem to open. It has a normal size, but Word or Adobe won’t open it. So can you do anything about that?
The first thing I will do is open the file in a hex editor. Most files include some information in the very top of the file which describes what kind of file it actually might be.
Below, is a character representation of an Adobe PDF file. Let’s say someone mistakenly saves a PDF file as a Microsoft Word .DOC file.
When your system sees that extension, it will try to launch Microsoft Word to open the file – but it will fail. Open the file in a hex editor, and it is immediately clear that this file is indeed a PDF file, and a quick switch to the file extension and you will be able to open it right up in Adobe Acrobat or other proper reader.
If you see a filetype but have no idea what kind of program might be used to open that file, you might check out OpenWith which lists many file extensions and the programs used to open them.
Game & File Hacking
Another popular reason you might use a hex editor is game hacking. You can load up a game save state file and change the amount of money you have from $1,000 to $1,000,000, for example.
Now, on more recent games this has been made much harder. Many modern games include either compression or encryption which make it many times more difficult to decompile the save state or game. However, some games still allow you to edit certain variables, such as in Sonic Spinball.
In addition to looking into game files, sometimes you can glean other important information from a saved file that you otherwise might not have access to. This depends greatly on the type of file and what information you are looking for, but using a hex editor is useful in determining what exactly resides within a file.
Debugging & Editing
Finally the last main reason you might use a hex editor is if you are a programmer who is debugging your code. Instead of going back to recompile you code, a simple hex edit might be all you need to test out a verification pattern. Editing a raw binary file is not recommended for the feint of heart – modify just one character in a file could potentially render it useless. Make sure you have a backup before modifying any files using a hex editor.
When a Hex Isn’t a Hex
Hopefully you’ve learned a little bit about computers that you hadn’t known before, or at least have had your memory refreshed. Knowing how your computer ticks becomes more and more important as they become easier and easier to use. I know if you made it this far, you are ready to use these advanced strategies for getting the most out of the bits and bytes stored on your hard drive!
Have questions about hexadecimal or hex editors in general? Let us know below!
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.