Skip to content
Buy me a coffee

Reading hex

tag: file-typestag: beginners

A byte is 8 bits, a number from 0 to 255. Hexadecimal (base 16) uses the digits 0–9 and then A–F for 10 to 15, so every byte is exactly two hex digits, from 00 to FF.

Decimal Binary Hex
0 00000000 00
10 00001010 0A
77 01001101 4D
90 01011010 5A
255 11111111 FF

Hex is often written with 0x in front, as in 0x4D, so it isn’t mistaken for a decimal number.

A hex dump has three columns:

00000000: 4d5a 9000 0300 0000 0400 0000 ffff 0000 MZ..............
  1. Offset: how far into the file this line starts, in hex.
  2. Bytes: 16 bytes per line, in hex.
  3. Text: the same bytes as characters. Anything unprintable shows as a dot.

Here the first two bytes, 4D 5A, are the letters MZ: the start of a Windows program (see Magic numbers).

Open any file of your own:

System Command
macOS, Linux xxd FILE | head
Windows (PowerShell) Format-Hex FILE | Select-Object -First 5

Or use a hex editor, such as HxD on Windows or ImHex anywhere.

Numbers bigger than one byte are often stored backwards, lowest byte first. The number 0x12345678 is stored as 78 56 34 12. That’s called little-endian, and Windows and most PCs use it. If a value in a hex dump looks scrambled, try reading its bytes in reverse.

Magic numbers: the bytes at the start of a file that say what it is.

One Reverse Look

"A little learning is a dangerous thing." ~ A. Pope

One Reverse Look · Made with ❤ · Your friendly knowledge seeker