Number base conversion is the process of expressing the same numeric value in a different positional numeral system. Every integer has one true value; the base only determines how that value is written. The number 255 in decimal, 0xFF in hexadecimal, 0b11111111 in binary, and 0377 in octal are all identical — they are four notations for the same quantity.

Convert numbers between bases instantly →

What Are Number Bases?

A number base (or radix) defines how many unique digits are available before the system “carries over” to the next column. The column values are powers of the base, reading right to left.

Binary (Base 2)

Uses only 0 and 1. Column values are powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, …

Binary is the native language of digital hardware. Every logical operation, memory cell, and CPU instruction ultimately reduces to sequences of bits. Developers encounter binary directly when working with bitwise operations, network masks, or hardware registers.

Octal (Base 8)

Uses digits 0–7. Column values are powers of 8: 1, 8, 64, 512, …

Octal is compact shorthand for binary: one octal digit represents exactly three bits. It fell out of general use but remains highly relevant in Unix/Linux for file permission masks — chmod 755 and chmod 644 are octal values.

Decimal (Base 10)

Uses digits 0–9. The system humans use by default. Most programming languages parse numeric literals as decimal unless prefixed otherwise.

Hexadecimal (Base 16)

Uses digits 0–9 and letters A–F. One hex digit represents exactly four bits, making it the most compact human-readable encoding for binary data.

Hex is everywhere in software: CSS colors (#FF5733), memory addresses (0x7ffee4b2c8a0), SHA hashes, MAC addresses, UUID fields, and binary file inspection all use hex notation.

How to Convert Between Bases

By Hand

Decimal to another base — repeated division:

To convert decimal 42 to binary:

42 ÷ 2 = 21 remainder 0
21 ÷ 2 = 10 remainder 1
10 ÷ 2 =  5 remainder 0
 5 ÷ 2 =  2 remainder 1
 2 ÷ 2 =  1 remainder 0
 1 ÷ 2 =  0 remainder 1

Read remainders bottom to top: 101010. So decimal 42 = binary 101010.

From another base to decimal — positional expansion:

To convert hex 2A to decimal:

2A = (2 × 16¹) + (10 × 16⁰)
   = 32 + 10
   = 42

In JavaScript

JavaScript’s parseInt and toString handle base conversion natively:

// Decimal to other bases
const n = 255;
console.log(n.toString(2));   // "11111111"  (binary)
console.log(n.toString(8));   // "377"       (octal)
console.log(n.toString(16));  // "ff"        (hex)

// Any base to decimal
console.log(parseInt("11111111", 2));  // 255
console.log(parseInt("377", 8));       // 255
console.log(parseInt("ff", 16));       // 255

// Base to base (go through decimal)
function convertBase(value, fromBase, toBase) {
  return parseInt(value, fromBase).toString(toBase);
}

console.log(convertBase("ff", 16, 2));   // "11111111"
console.log(convertBase("377", 8, 16));  // "ff"

In Python

Python provides built-in functions and prefix literals:

# Decimal to other bases
n = 255
print(bin(n))    # '0b11111111'
print(oct(n))    # '0o377'
print(hex(n))    # '0xff'

# Strip the prefix if needed
print(format(n, 'b'))   # '11111111'
print(format(n, 'o'))   # '377'
print(format(n, 'x'))   # 'ff'
print(format(n, 'X'))   # 'FF'  (uppercase)

# Any base to decimal
print(int('11111111', 2))  # 255
print(int('377', 8))       # 255
print(int('ff', 16))       # 255

# Direct prefix literals
print(0b11111111)  # 255
print(0o377)       # 255
print(0xFF)        # 255

When Each Base Is Used in Programming

Binary — Bitwise Operations and Flags

Binary is the natural fit whenever you’re working at the bit level:

// Permission flags using bit masks
const READ    = 0b100;  // 4
const WRITE   = 0b010;  // 2
const EXECUTE = 0b001;  // 1

const userPerms = READ | WRITE;   // 0b110 = 6
const canRead   = userPerms & READ;   // truthy if permission set
const canExec   = userPerms & EXECUTE; // 0 — no execute

Network programming uses binary masks for subnet calculations. Hardware drivers use binary to set individual control bits in registers.

Octal — Unix File Permissions

The chmod command takes octal arguments. Three octal digits encode owner/group/other permissions, where each digit is r=4, w=2, x=1:

chmod 755 script.sh   # rwxr-xr-x
chmod 644 config.txt  # rw-r--r--
chmod 600 id_rsa      # rw------- (private key)

In Python, file modes passed to os.open and os.chmod should be octal literals:

import os
os.chmod('script.sh', 0o755)

Hexadecimal — Colors, Addresses, and Binary Data

CSS and design: RGB colors map directly to three hex byte pairs.

/* #RRGGBB */
color: #FF5733;   /* R=255, G=87, B=51 */
color: #1a1a2e;   /* dark navy */

Memory and pointers: Debuggers and crash dumps display addresses in hex because the values align cleanly with 4-bit nibbles and 8-bit bytes.

Hashing and encoding: SHA-256 output, git commit hashes, UUIDs, and API keys are conventionally hex-encoded binary data.

import hashlib
h = hashlib.sha256(b"hello").hexdigest()
print(h)  # 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Network protocols: Ethernet frames, IP headers, and TLS records are all inspected in hex in tools like Wireshark.

Convert Numbers Online

For quick conversions without writing code, ZeroTool’s Number Base Converter converts any integer between binary, octal, decimal, and hexadecimal instantly in your browser. Paste a value in any field and all other bases update in real time — no server requests, no data sent anywhere.

Useful for:

  • Decoding hex color values to decimal RGB
  • Converting octal chmod values to verify permissions
  • Exploring binary representations for bitwise logic
  • Translating memory addresses between formats

Try the ZeroTool Number Base Converter →