Skip to content
CodeShift
Menu

Binary vs. Hexadecimal: What's the Difference?

Binary uses base 2 (digits 0–1); hex uses base 16 (digits 0–9 and A–F). One hex digit equals exactly 4 binary digits, making hex a compact shorthand.

By The CodeShift DeskPublished September 3, 2026

Binary (base 2) uses only 0 and 1. Hexadecimal (base 16) uses 0–9 plus A–F. The key relationship: one hex digit always equals exactly 4 binary digits (bits), so one byte = 2 hex digits. Programmers choose hex because it is far more compact while remaining directly convertible to binary without arithmetic.

The Two Alphabets Side by Side

Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F

Once you memorize this table, you can translate between binary and hex by inspection — no division required.

Converting a Byte: Binary to Hex

Take the byte 01000001 (the letter A in ASCII, decimal 65).

  1. Split into two nibbles (groups of 4): 0100 and 0001.
  2. Convert each nibble: 0100 = 4, 0001 = 1.
  3. Write the hex digits: 41.

So 65 in decimal = 01000001 in binary = 41 in hex. You can verify with the hex converter.

A more complex example: the byte 11111111 (decimal 255).

  • Left nibble 1111 = F
  • Right nibble 1111 = F
  • Result: FF

That is why 0xFF appears in code as the maximum single-byte value.

Where Each Format Appears

Format Typical use
Binary Circuit design, boolean logic, low-level bit ops
Hexadecimal Memory addresses, color codes (#FF5733), file dumps
Decimal Human-facing numbers and counts

Web colors use 6-digit hex: #RRGGBB. The color #FF0000 is pure red — red channel at 255 (FF), green at 0, blue at 0.

Unicode code points are written in hex. The letter A is U+0041 (hex 41, decimal 65). The euro sign is U+20AC (hex 20AC, decimal 8364).

Converting Hex Back to Binary

Each hex digit expands to exactly 4 bits:

  • A = 1010
  • F = 1111
  • 0 = 0000

So AF in hex = 1010 1111 in binary = 175 in decimal.

No intermediate decimal step is needed. That direct mapping is why hex exists — it is shorthand binary, nothing more.

When to Use Which

Use binary when you need to inspect or manipulate individual bits — checking flags, writing bitmasks, or understanding how data is physically stored.

Use hex when you are reading memory dumps, writing color values, specifying Unicode code points, or working with byte streams where visual compactness matters.

Use decimal for everything a human normally counts or measures.

Octal: A Third System Worth Knowing

Hexadecimal has largely replaced octal (base 8) in modern computing, but you still encounter octal in Unix file permissions. The permission mask 0755 is an octal number: the leading zero signals octal in C, Python 2, and several shell environments. Each octal digit represents exactly 3 bits (not 4), so converting between octal and binary is also direct — just a smaller grouping.

Octal Binary Decimal
0 000 0
1 001 1
7 111 7

Unix permission rwxr-xr-x in binary is 111 101 101 = octal 755. Once you see the three-bit grouping, permission math becomes mechanical.

Practical Cheat Sheet

Task Best format
Reading a file’s bytes in a hex editor Hex
Checking a network bitmask Binary
Writing a CSS color Hex (#RRGGBB)
Setting Unix permissions Octal
Any normal human math Decimal

Hex editors show files as two-column pairs of hex digits (one byte each) alongside an ASCII interpretation on the right. When you see 48 65 6C 6C 6F, you know the byte values are 72, 101, 108, 108, 111 — the ASCII codes for “Hello”. Converting those two-digit hex pairs to binary mentally (4 bits per digit) takes seconds with the table above memorized.

See How to Read Binary for a full positional breakdown, or Bits and Bytes Explained to understand how these units group together in real systems.

Frequently asked questions

Why do programmers use hex instead of binary?+

One hex digit represents exactly 4 bits, so a byte is two hex digits instead of eight binary digits. FF is much faster to read and write than 11111111.

What does 0xFF mean?+

The prefix 0x marks a hexadecimal number. 0xFF equals decimal 255, or 11111111 in binary — the maximum value of one byte.

Is hex the same as Base16?+

Yes. Hexadecimal and Base16 are the same thing. The name hexadecimal comes from the Greek hex (six) plus the Latin decimus (tenth), reflecting its 16-symbol set.

How do I convert hex to binary?+

Replace each hex digit with its 4-bit binary equivalent. F = 1111, A = 1010, 0 = 0000, and so on. The 2-digit hex byte FF becomes 11111111 in binary.

What is the hex color code for white?+

White in RGB is #FFFFFF — three bytes of value 255 each, one per color channel (red, green, blue).

Keep reading