ReferenceMarch 15, 20263 min read

Number Base Conversion: Binary, Octal, Decimal, and Hexadecimal

Understand how numbers are represented in different bases and why programmers constantly switch between binary, hex, decimal, and octal.

Why Computers Use Different Number Systems

Humans count in base 10 because we have ten fingers. Computers operate in base 2 because transistors have two states — on and off. Programmers use base 16 because it compactly represents binary data. These are not arbitrary choices — each base serves a specific purpose.

The Four Common Bases

Binary (Base 2) — Digits: 0, 1. This is how computers actually store and process numbers. Each digit is a bit. The number 42 in binary is 101010. Binary is fundamental but tedious to read for large values.

Octal (Base 8) — Digits: 0–7. Each octal digit represents exactly 3 binary digits. Used historically in Unix file permissions (chmod 755) and some older computing contexts. Less common today but still appears in specific domains.

Decimal (Base 10) — Digits: 0–9. The system humans use daily. When you see "42" with no prefix, it is decimal. Computers must convert between decimal and binary internally for every calculation.

Hexadecimal (Base 16) — Digits: 0–9, A–F (where A=10, B=11, C=12, D=13, E=14, F=15). Each hex digit represents exactly 4 binary digits. The number 42 in hex is 2A. Hex is universally used in programming for colors (#FF5733), memory addresses (0x7FFE), byte values, and any context where binary data needs a human-readable representation.

How Positional Notation Works

In any base, the value of a digit depends on its position. Each position represents a power of the base:

In decimal, 42 means: (4 × 10¹) + (2 × 10⁰) = 40 + 2 = 42

In binary, 101010 means: (1 × 2⁵) + (0 × 2⁴) + (1 × 2³) + (0 × 2²) + (1 × 2¹) + (0 × 2⁰) = 32 + 0 + 8 + 0 + 2 + 0 = 42

In hex, 2A means: (2 × 16¹) + (10 × 16⁰) = 32 + 10 = 42

The same value, represented differently depending on the base.

Why Hex Is the Programmer's Best Friend

A single byte (8 bits) stores values from 0 to 255. In binary, that range is 00000000 to 11111111 — 8 characters. In hex, it is 00 to FF — just 2 characters. Hex is a compact, readable representation of binary data.

This is why hex appears everywhere in programming:

  • Colors: #FF0000 = red (255 red, 0 green, 0 blue)
  • Memory addresses: 0x7FFEE3B4A000
  • Character codes: Unicode code point U+0041 = the letter A
  • MAC addresses: AA:BB:CC:DD:EE:FF
  • Error codes: 0xDEADBEEF (a famous debugging sentinel)

Converting Between Bases

Decimal to binary: Repeatedly divide by 2 and record remainders. 42 ÷ 2 = 21 r 0, 21 ÷ 2 = 10 r 1, 10 ÷ 2 = 5 r 0, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1. Read remainders bottom-up: 101010.

Binary to hex: Group binary digits in sets of 4 from the right. 0010 10102 A2A.

Hex to binary: Replace each hex digit with its 4-bit binary equivalent. 2A0010 1010.

How to Use the Toobits Number Base Converter

Enter a number in any base — binary, octal, decimal, or hexadecimal — and instantly see the equivalent in all other bases. The tool validates input characters for the selected base and updates all conversions in real time. Everything runs in your browser.

Try These Tools

Related Articles