Skip to content
Converters 7 min read

Number Bases for Developers: Binary, Octal, Decimal, Hex

Learn how binary, octal, decimal, and hexadecimal number systems work, how to convert between them, and where each base appears in real programming tasks.

ToolsVito Team

Why Different Bases Matter

Computers operate in binary (base 2). Humans use decimal (base 10). Hexadecimal (base 16) is a compact representation of binary that maps cleanly — each hex digit represents exactly 4 bits. Octal (base 8) appears in Unix file permissions. Understanding all four lets you reason about memory addresses, bitwise operations, color values, and cryptographic output without confusion.

Binary (Base 2)

Only digits 0 and 1. Each position is a power of 2:

1011₂ = 1×2³ + 0×2² + 1×2¹ + 1×2⁰
      = 8 + 0 + 2 + 1
      = 11₁₀

Binary appears in: bitwise operations, flags, network masks, bit manipulation, storage of booleans.

// JavaScript bitwise operators work on 32-bit integers
const flags = 0b1010;   // binary literal
flags & 0b0010;         // AND: 0b0010 (2) — is bit 1 set?
flags | 0b0001;         // OR:  0b1011 — set bit 0
flags ^ 0b1111;         // XOR: 0b0101 — toggle all bits
~flags;                 // NOT: invert all bits

Octal (Base 8)

Digits 0–7. Each position is a power of 8. Most common in Unix file permissions:

chmod 755 file.sh
  7 = 111₂ = rwx (owner: read, write, execute)
  5 = 101₂ = r-x (group: read, execute)
  5 = 101₂ = r-x (other: read, execute)

// In JavaScript — octal literal (prefix 0o)
0o755 === 493   // decimal equivalent

Hexadecimal (Base 16)

Digits 0–9 and A–F (10–15). One hex digit = 4 bits = one nibble. Two hex digits = 8 bits = one byte.

0xFF = 1111 1111₂ = 255₁₀
0x1A = 0001 1010₂ = 26₁₀

// Common hex in practice:
#ff4d8b    ← CSS color (R=0xFF=255, G=0x4D=77, B=0x8B=139)
0x7FFFFFFF ← INT32_MAX
0xDEADBEEF ← classic debug marker
ÿþ   ← UTF-16 BOM bytes

Converting in JavaScript

// Decimal to other bases
(255).toString(2)   // "11111111" — to binary
(255).toString(8)   // "377"      — to octal
(255).toString(16)  // "ff"       — to hex

// Parse from other bases (second arg = radix)
parseInt("11111111", 2)  // 255
parseInt("377", 8)       // 255
parseInt("ff", 16)       // 255

// Literals in JS
0b11111111  // binary
0o377       // octal
0xff        // hex

Converting in Python

bin(255)   # "0b11111111"
oct(255)   # "0o377"
hex(255)   # "0xff"

int("11111111", 2)  # 255
int("377", 8)       # 255
int("ff", 16)       # 255

Memory Addresses and Pointers

Hex is universal for memory addresses. A 64-bit system uses addresses like 0x7fff5fbff8a0 — 48 bits, 12 hex digits. Debuggers, core dumps, and security tools all display addresses in hex because it maps cleanly to bit boundaries.

Convert Number Bases Instantly

Use ToolsVito's Number Base Converter to convert between binary, octal, decimal, and hexadecimal with step-by-step calculation.

Try it now — free, runs in your browser

Number Base Converter

Binary, octal, decimal, hex