(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Hexadecimal (often simply called "hex") is a special way of counting where 16 numerals are used in a single place-holder instead of the 10 used in standard decimal. This allows you to write larger numbers with less space. Here are the first 32 numbers with their hex equivalents.

```Decimal:  00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
Hex:      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20
```

The primary benefit of hex is seen when displaying computer data because computers store information in bytes. A byte can have a value from 0-255. Displaying a byte in decimal requires three placeholders, but in hex, it only takes 2 because 255 in decimal is represented as FF in hex. This savings adds up quickly when viewing long strings of numbers like those in NES ROMs.

Also, computers do everything in binary (1 or 0), and hex is well suited for working with binary and performing calculations in binary. Look at this chart of bit toggling. The values being similar, but as the numbers get larger, the decimal values begin to become more complex, but the hex numbers remain simple to work with.

```Binary    Dec  Hex
00000000  000  00
00000001  001  01
00000010  002  02
00000100  004  04
00001000  008  08
00010000  016  10
00100000  032  20
01000000  064  40
10000000  128  80
11111111  255  FF
```

When you look at NES memory, and hex editors in general, everything is displayed in hex to make it easier to view the data. There is a learning curve for beginners, but once you become used to viewing data in hex, you'll never want to go back to decimal.

Here's FCEUX's hex editor for viewing NES memory.

Some hex numbers look identical to decimal numbers, but have different values. For example, 12 in hex looks the same as 12 in decimal, but 12 in hex has a decimal value of 18. When displaying hex and decimal values in the same document, the dollar sign (\$) is used to identify which numbers are hex. Thus, 12 = 12, but \$12 = 18. Hex is also sometimes identified by placing an "h" after the number (12h) or a zero and an "x" in front of the number (0x12). Nearly all of the values used in the NES Hacker Wiki will be in hex, so don't worry about a signifier.

If you want to quickly convert hex into decimal and vice-verse, most operating systems come with a free calculator that can perform simply hex conversions. For the Windows calculator, switch to the "Programmer" view (Menu -> View -> Programmer), and then click the hex radio button on the left to convert the number.