Back to tools

Base

Number Base Converter

Convert between binary, octal, decimal, and hexadecimal online. Enter a value in any field to update the others with invalid format warnings.

Base inputs

Visible bases Select only the bases you need to keep the workspace focused.

Conversion rules

Positional expansion

Any base-N number can be expanded by multiplying each digit by its power of N and summing the result.

101010₂ = 1×2⁵ + 0×2⁴ + 1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 42₁₀

Decimal to another base

Repeatedly divide by the target base, record remainders, then read the remainders in reverse order.

42 ÷ 16 = 2 ... 10(A)
2 ÷ 16 = 0 ... 2
42₁₀ = 2A₁₆

Valid digits

Base N only allows digits smaller than N. Bases above 10 use A-Z for 10-35, so A is 10 in hexadecimal and Z is 35 in base36.

0b101010 = 0o52 = 42 = 0x2A

Common base conversion code

JavaScript

const value = BigInt("42");
const binary = value.toString(2);
const octal = value.toString(8);
const hex = value.toString(16).toUpperCase();

Python

value = int("2A", 16)
binary = bin(value)[2:]
octal = oct(value)[2:]
hex_value = hex(value)[2:].upper()

Java

long value = Long.parseLong("2A", 16);
String binary = Long.toString(value, 2);
String octal = Long.toString(value, 8);
String hex = Long.toString(value, 16).toUpperCase();

Go

value, _ := strconv.ParseInt("2A", 16, 64)
binary := strconv.FormatInt(value, 2)
octal := strconv.FormatInt(value, 8)
hex := strings.ToUpper(strconv.FormatInt(value, 16))

C#

var value = Convert.ToInt64("2A", 16);
var binary = Convert.ToString(value, 2);
var octal = Convert.ToString(value, 8);
var hex = Convert.ToString(value, 16).ToUpperInvariant();

PHP

$value = intval("2A", 16);
$binary = base_convert((string)$value, 10, 2);
$octal = base_convert((string)$value, 10, 8);
$hex = strtoupper(base_convert((string)$value, 10, 16));