Number Base Converter

Paste an integer in any base and get binary, octal, decimal and hex back at once.

From base
Negative numbers

How to use

  1. Paste a number (with a 0x, 0b or 0o prefix, or plain decimal digits) or pick its base explicitly from From base.
  2. Read the four results: binary, octal, decimal and hexadecimal, all computed from the same parsed value. Under them, the Bit map shows the binary in groups of four with each group's hex digit above it (hover a bit for its position), and In fixed-width storage shows how the value reads as an unsigned and a signed 8, 16, 32 and 64-bit integer.
  3. For a negative number, tick Show as two's complement and pick the Bit width if you need the fixed-width bit pattern rather than a plain minus sign.
  4. Click any result to copy it: the prefix (0x/0b/0o) is included so it pastes straight into most languages' source code.

Why more than one way to write the same number

Binary is what the hardware actually stores; hexadecimal is a compact, human-readable stand-in for binary (each hex digit is exactly 4 bits, so conversion between them is mechanical); octal shows up mostly in Unix file permissions and some older systems; decimal is what everyone reads and writes by hand. Reading a value in one base while thinking in another (a permission bitmask, a color's hex packed into a 32-bit integer, a memory address) is common enough that doing the arithmetic by hand is both slow and easy to get wrong.

Example

The number 0xCAFEBABE (the magic number at the start of every compiled Java .class file) is, in every base:

0b11001010111111101011101010111110
0o31277535276
3405691582
0xcafebabe

Options explained

Edge cases and common errors

Do the same thing in code

// JavaScript
(3405691582).toString(16);   // 'cafebabe'
parseInt('cafebabe', 16);    // 3405691582 (loses precision above 2**53)
BigInt('0xcafebabe');        // 3405691582n (exact at any size)

# Python
hex(3405691582)              # '0xcafebabe'
int('cafebabe', 16)          # 3405691582 (Python ints have no size limit)

Python's integers are arbitrary-precision by default, so it never has the precision problem JavaScript's plain Number does. This tool uses JavaScript's BigInt for the same reason Python doesn't need one.

Number Base Converter FAQ

How does it know which base I typed?

By the prefix: 0x for hexadecimal, 0b for binary, 0o for octal, the same convention JavaScript, Python, Rust and C all use in source code. Anything with no recognised prefix is read as plain decimal. Set From base explicitly if your input has no prefix and is not decimal.

Why does a very large hex value convert without losing digits?

Because the conversion is done with an arbitrary-precision integer type, not a plain JavaScript number, which starts losing precision above 253. 0xFFFFFFFFFFFFFFFF (264 − 1) converts exactly to 18446744073709551615; a plain-number implementation would round that.

What’s the difference between a plain minus sign and two’s complement?

By default, a negative number just gets a minus sign in every base: -5 in binary is -101, which is simple but only meaningful if you already know the number is signed. Two’s complement instead encodes the sign into a fixed number of bits, the way processors and most typed languages actually store signed integers: -5 as a signed 8-bit integer is 11111011. Turn it on when you need the bit pattern a real 8/16/32/64-bit signed variable would hold.

What happens if a number does not fit in the bit width I picked?

It is rejected rather than silently wrapped or truncated: 200 does not fit as a signed 8-bit integer (whose range is −128 to 127), so it stops with "200 does not fit in a signed 8-bit integer (range -128 to 127)". Pick a wider bit width, or use the plain minus-sign form instead.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta.