Understanding Number Systems: Binary, Decimal, and Hexadecimal

Learn how binary, decimal, and hexadecimal number systems work and how to convert between them.

The Quick Answer

System Base Digits Used Example
Binary 2 0, 1 1010
Decimal 10 0-9 10
Hexadecimal 16 0-9, A-F A

All three represent the same value: ten

Why Different Number Systems?

Decimal (base 10): Humans use it because we have 10 fingers.

Binary (base 2): Computers use it because transistors have two states: on/off.

Hexadecimal (base 16): Programmers use it as a compact way to represent binary (4 binary digits = 1 hex digit).

How Number Systems Work

Decimal (What You Know)

Each position is a power of 10:

  2   5   3
  │   │   └── 3 × 10⁰ = 3 × 1   = 3
  │   └────── 5 × 10¹ = 5 × 10  = 50
  └────────── 2 × 10² = 2 × 100 = 200
                                  ───
                                  253

Binary (Base 2)

Each position is a power of 2:

  1   0   1   1
  │   │   │   └── 1 × 2⁰ = 1 × 1 = 1
  │   │   └────── 1 × 2¹ = 1 × 2 = 2
  │   └────────── 0 × 2² = 0 × 4 = 0
  └────────────── 1 × 2³ = 1 × 8 = 8
                                   ──
                                   11 (decimal)

Hexadecimal (Base 16)

Each position is a power of 16. Uses A-F for 10-15:

Hex Decimal
A 10
B 11
C 12
D 13
E 14
F 15
  2   F
  │   └── F × 16⁰ = 15 × 1  = 15
  └────── 2 × 16¹ = 2 × 16  = 32
                              ──
                              47 (decimal)

Converting Between Systems

Binary to Decimal

Add up the powers of 2 where there's a 1:

Binary: 11010

Position:  4  3  2  1  0
Value:    16  8  4  2  1
Binary:    1  1  0  1  0

= 16 + 8 + 0 + 2 + 0 = 26

Decimal to Binary

Repeatedly divide by 2, track remainders:

26 ÷ 2 = 13 remainder 0
13 ÷ 2 = 6  remainder 1
6  ÷ 2 = 3  remainder 0
3  ÷ 2 = 1  remainder 1
1  ÷ 2 = 0  remainder 1

Read bottom to top: 11010

Hex to Decimal

Multiply each digit by its power of 16:

Hex: 1A3

= 1 × 16² + A × 16¹ + 3 × 16⁰
= 1 × 256 + 10 × 16 + 3 × 1
= 256 + 160 + 3
= 419

Decimal to Hex

Repeatedly divide by 16:

419 ÷ 16 = 26 remainder 3
26  ÷ 16 = 1  remainder 10 (A)
1   ÷ 16 = 0  remainder 1

Read bottom to top: 1A3

Binary to Hex (Shortcut)

Group binary digits into sets of 4 (from right), convert each group:

Binary: 11010110

Group:  1101  0110
Hex:      D     6

Result: D6

Hex to Binary (Shortcut)

Convert each hex digit to 4 binary digits:

Hex: A7

A = 1010
7 = 0111

Result: 10100111

Common Values Reference

Decimal Binary Hex
0 0000 0
1 0001 1
5 0101 5
10 1010 A
15 1111 F
16 10000 10
100 1100100 64
255 11111111 FF
256 100000000 100

Where You'll See These

Binary

  • Low-level programming
  • Bit flags and permissions
  • Network subnet masks
  • File permissions (chmod)

Hexadecimal

  • Colors in CSS: #FF5733
  • Memory addresses: 0x7fff5fbff8ac
  • MAC addresses: 00:1A:2B:3C:4D:5E
  • Unicode: U+1F600
  • Cryptographic hashes

Prefixes in Code

let decimal = 42;      // No prefix
let binary = 0b101010; // 0b prefix
let hex = 0x2A;        // 0x prefix
let octal = 0o52;      // 0o prefix (base 8)

Colors in Hex

CSS colors use hex because each color channel (R, G, B) fits in one byte (0-255 = 00-FF):

#FF5733
  ││││││
  ││││└┴── Blue:  33 = 51
  ││└┴──── Green: 57 = 87
  └┴────── Red:   FF = 255
Convert Numbers

Base Converter

Convert numbers between any bases from 2 to 36.

Open Converter

Related Tools

Related Tools