Binary, Octal and Hexadecimal: Understanding Number Bases

How the decimal, binary, octal and hexadecimal number systems work, why computers use binary, and how to convert between them.

We count in decimal (base-10) because we have ten fingers. Computers use binary (base-2) because their transistors are either on or off. Understanding number bases helps in programming, web design (CSS colours), and digital electronics.

The four common bases

Base Name Digits Used in
10 Decimal 0–9 Everyday math
2 Binary 0–1 Computer hardware, logic
8 Octal 0–7 Unix permissions, compact binary
16 Hexadecimal 0–9, A–F Memory addresses, CSS colours

How binary works

Binary (base-2) uses only 0 and 1. Each position represents a power of 2: 1, 2, 4, 8, 16, 32, 64, 128. The number 11111111 in binary is 255 in decimal (128+64+32+16+8+4+2+1).

Worked example: Convert 255 decimal to binary. Divide by 2 repeatedly and read remainders bottom to top:

  • 255 ÷ 2 = 127 remainder 1
  • 127 ÷ 2 = 63 remainder 1
  • 63 ÷ 2 = 31 remainder 1
  • 31 ÷ 2 = 15 remainder 1
  • 15 ÷ 2 = 7 remainder 1
  • 7 ÷ 2 = 3 remainder 1
  • 3 ÷ 2 = 1 remainder 1
  • 1 ÷ 2 = 0 remainder 1

Result: 11111111. Use the base converter to verify.

Hexadecimal in everyday life

HTML colours use hex: #FF5733 means red=FF (255), green=57 (87), blue=33 (51). One hex digit maps exactly to four binary digits, making it a compact way to read binary. A byte (0–255) is exactly two hex digits (00–FF).

Why programmers use hex

Hex is more compact than binary and maps cleanly to bytes. Memory addresses, CPU registers, and debug output are shown in hex because it is easier to read than long strings of 1s and 0s.

Frequently asked questions

Why do programmers use hexadecimal? Hex is more compact than binary (one hex digit = four binary digits) and maps cleanly to bytes. A byte value 0–255 is exactly two hex digits 00–FF.

What does 0x mean? The prefix 0x indicates a hexadecimal number in programming. For example, 0xFF = 255 in decimal.

How do I read binary quickly? Group digits in fours from the right and convert each group to hex. 1111 1111 = FF = 255. It is easier to read binary as hex than as decimal. The exponents explained guide covers the power-of-2 foundation that binary depends on.