Page 1 of 1

ShaneM's Guide to Hex Editing

PostPosted: December 8th, 2013, 4:27 am
by ShaneM
Definition taken from Wikipedia, the rest by me, ShaneM.

A hex editor (or binary file editor or byte editor) is a type of computer program that allows for manipulation of the fundamental binary data that constitutes a computer file. The name 'hex' comes from 'hexadecimal': the standard numerical format for editing binary data. A typical computer file occupies multiple areas on the platter(s) of a disk drive, whose contents are combined to form the file. Hex editors that were designed to parse and edit sector data from the physical segments of floppy or hard disks were sometimes called sector editors or disk editors.


Okay, so the game is read and interpreted by the CPU as binary (0's and 1's). Since it is difficult to edit that way, we use a system known as the hexadecimal, which uses 0-F. The third system is the decimal, which uses 0-9, but that won't be covered here. Now, the numbers within a hex editor goes from left to right. Whenever you see '0x' that is equivalent to an offset, or address within the ROM. So, upon opening a hex editor, you will see 00000000 at the upper left. If you click on the second byte next to it it will say 00000001. That is known as an offset, or address. So, if I say to replace the byte at 0x10 with $40, I'm telling you to change the value at the sixteenth byte with $40.

How do you know what that data means within a hex editor? You can use a debugger, a disassembly, or even a site that defines data for a specific game. (I will cover how to use debuggers in another lesson.) Binary can be useful for flags within a game. Since there are 8 bits in 1 byte, binary can be useful for setting flags. A set bit is when a bit is changed from 0 to 1. A reset bit is when a bit is changed to 0.

But how do you edit flags within hex? Simple. Grab Windows calculator, or another calculator with programming capabilities, type a number in hex, like $FF. Next, click on binary. You should get 11111111. So, if you want to make a bit reset, let's say, with the rightmost bit, you would type in the calculator 11111110, then, click hex and you get $FE!

If you have any questions, reread this amongst yourself, then ask for my help. Thank you.