ToolSec

๐Ÿ” Crypto & Encoding

Hexadecimal Explained: Why Programmers Use Hex

ยท 6 min read ยท Updated June 27, 2026

Hexadecimal shows up everywhere in programming โ€” color codes, memory addresses, hashes, MAC addresses โ€” yet it's rarely explained well. The good news: once you see how it maps to binary, it's genuinely simple.

What is hexadecimal?

Hexadecimal (or "hex") is base 16. Where decimal uses ten digits (0โ€“9), hex uses sixteen: 0โ€“9 then aโ€“f for the values ten through fifteen. So a is 10, f is 15, and 10 in hex is sixteen in decimal. Hex values are often written with a 0x prefix, like 0xFF, to distinguish them from decimal.

Why programmers love hex: the binary mapping

Computers work in binary, but long strings of 0s and 1s are painful for humans to read. Hex solves this neatly because one hex digit equals exactly four bits (since 16 = 2โด). That means:

  • Four bits (a "nibble") = one hex digit.
  • Eight bits (one byte) = exactly two hex digits.

So the byte 11111111 in binary is simply FF in hex โ€” far easier to read and type. This clean, lossless mapping is the whole reason hex is the preferred shorthand for binary data.

Where you'll see hex

  • Colors: #FF5733 is red=FF, green=57, blue=33 โ€” three bytes, six hex digits.
  • Memory addresses in debuggers and crash logs.
  • Hashes and checksums: an MD5 or SHA digest is shown as hex.
  • MAC addresses: six bytes like 00:1A:2B:3C:4D:5E.
  • Byte-level data in hex editors and packet captures.

Converting hex to decimal

Each position is a power of 16. For 0x2F: the 2 is in the sixteens place (2 ร— 16 = 32) and F is 15, so 32 + 15 = 47. Going the other way, you repeatedly divide by 16. In practice, you'll just use a converter โ€” the point is to understand what the number means.

Octal: the other base you'll meet

You'll occasionally see octal (base 8), most famously in Unix file permissions like chmod 755. Each octal digit maps to exactly three bits. It's less common than hex today but worth recognising.

Hex of bytes vs hex of text

Two related but different ideas: converting a number between bases (decimal โ†” hex), and converting text to its hex byte representation (where "Hi" becomes 4869 via its UTF-8 bytes). Make sure you're using the right tool for the job.

Try it

Convert numbers between binary, octal, decimal and hex with our number base converter, and turn text into its hex bytes (or back) with the hex โ†” text converter. For a different printable representation of bytes, see what Base64 is.

Frequently asked questions

Why do programmers use hexadecimal?

Because one hex digit maps to exactly four bits and two hex digits to one byte. That makes hex a compact, lossless shorthand for binary data โ€” 0xFF is far easier to read than 11111111.

How do I convert hex to decimal?

Each position is a power of 16. For 0x2F: 2 ร— 16 = 32 plus F (15) = 47. In practice a base converter does it instantly, but understanding the place values helps.

What does the 0x prefix mean?

It signals that the number is written in hexadecimal, to avoid confusion with decimal. 0xFF and FF mean the same value; the prefix is just a convention used in code.

Try the related tools

Related guides