This tool converts whole numbers between binary, octal, decimal and hexadecimal in your browser; nothing leaves your machine. It uses arbitrary-precision integers (BigInt), so 64-bit and larger values convert exactly.
What “base” means
A number’s base is how many digits its positional notation uses:
| Base | Digits | Example: 42 in this base |
|---|---|---|
| 2 (binary) | 0, 1 | 101010 |
| 8 (octal) | 0–7 | 52 |
| 10 (decimal) | 0–9 | 42 |
| 16 (hex) | 0–9, a–f | 2a |
Each digit’s value is its symbol multiplied by the base raised to its position:
42 in decimal:
4 × 10¹ + 2 × 10⁰ = 40 + 2 = 42
42 in hex (= "2a"):
2 × 16¹ + 10 × 16⁰ = 32 + 10 = 42
42 in binary (= "101010"):
1 × 32 + 0 × 16 + 1 × 8 + 0 × 4 + 1 × 2 + 0 × 1 = 42
The underlying value is the same; only the notation differs.
When each base shows up
- Binary — bit-level operations, hardware register layouts, bitfield manipulation, encoding/decoding tables. See binary to text for byte-level binary representation.
- Octal — Unix file permissions (
chmod 755), some C string escapes (\041). Mostly historical; rarely seen in new code. - Decimal — everything humans read.
- Hex — color values (
#ff0066), memory addresses, byte dumps (xxd), MAC addresses, UUIDs, hash digests, Unicode code points. The default for “machine values displayed for humans.”
For hex specifically, see hex to text for the byte-decoding case.
Programming notation
Most programming languages have a syntax for non-decimal literals:
Decimal: 42
Hex: 0x2a (C, Java, Python, JS, Ruby, Go, Rust)
Octal: 052 (C — leading 0)
0o52 (Python 3, JS, Rust — explicit prefix)
Binary: 0b101010 (Python, Java 7+, JS ES2015+, Rust, Go 1.13+)
The C-style leading-0 for octal (052) is a notorious source of bugs — anyone who writes 015 thinking they mean fifteen has probably been burned by it being thirteen. Modern languages use 0o for octal.
Negative numbers
Two common conventions for representing negative numbers in binary:
- Sign-magnitude — first bit is the sign, rest is magnitude.
-5in 8-bit is10000101(sign bit set, value 5). - Two’s complement — most common in modern computers.
-5in 8-bit is11111011(the two’s complement of 5).
Two’s complement is dominant because addition works without special-casing the sign — the same circuit adds 5 + (-5) correctly.
The tool above keeps the minus sign: -42 in decimal becomes -101010 in binary (a signed magnitude, not a fixed-width bit pattern). For the two’s complement form, pick a width and add 2ⁿ yourself — -42 in 8 bits is 256 − 42 = 214 = 11010110.
Floating point
Bases conversion gets complicated for non-integers. 0.1 in decimal is not representable exactly in binary — it’s a repeating fraction:
0.1 (decimal) = 0.0001100110011... (binary, repeating)
This is why 0.1 + 0.2 !== 0.3 in JavaScript and most other languages. The decimal-to-binary conversion of 0.1 is approximated, and the approximation propagates.
For exact decimal arithmetic, languages provide arbitrary-precision decimal types (Python’s Decimal, JavaScript’s BigInt plus careful scaling, financial libraries with fixed-point). Don’t use floating-point for currency.
The tool above handles integers only, and exactly; it rejects input with a decimal point.
Bit width
Integers in computers have fixed bit widths: 8, 16, 32, or 64 bits. The conversion result depends on the width:
Decimal 257:
As 8-bit: overflows (only 0–255 fit)
As 16-bit binary: 0000000100000001
As 32-bit binary: 00000000000000000000000100000001
The tool above shows minimum-width output (no leading zeros); pad to 8, 16, 32 or 64 digits yourself when you need a fixed width.
Letters above 9
For bases > 10, digits beyond 9 are written as letters: a = 10, b = 11, …, z = 35. So base 36 uses 0–9 and a–z. Bases above 36 don’t have a universal convention.
Hex (base 16) uses a-f. Mixed case is conventional: 0xFF and 0xff are the same number. The tool above accepts either case (and an optional 0x, 0b or 0o prefix) and emits upper-case hex.
Common pitfalls
- Mistaking hex for decimal.
12is twelve in decimal but eighteen in hex. Always verify the base. - Leading-zero octal.
08and09are invalid in C-style octal (octal digits are 0–7); a leading-zero09is either a syntax error or treated as decimal 9 depending on the parser. - JavaScript
parseIntquirks.parseInt("08")is0in pre-ES5 JavaScript (octal interpretation) and8in modern JavaScript. Always pass the radix:parseInt("08", 10). - Lost precision with very large numbers. A 64-bit integer (like a Twitter ID) doesn’t fit in JavaScript’s
Numbertype and gets rounded. UseBigIntor string handling for large integers. - Confusion between bit count and number of digits.
0xffis two hex digits but eight bits.0xffffis four hex digits but sixteen bits. Each hex digit = 4 bits.
For other byte-level tools, see hex to text, text to hex, binary to text, ASCII table.