How to use
- Paste a number (with a
0x,0bor0oprefix, or plain decimal digits) or pick its base explicitly from From base. - 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.
- 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.
- 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
0xcafebabeOptions explained
- From base: Auto-detect / Binary / Octal / Decimal / Hexadecimal: Auto-detect reads the
0x/0b/0oprefix if present and otherwise assumes decimal; pick a base explicitly for input with no prefix that is not decimal (plainff, for instance, is ambiguous between hex and an invalid decimal number without it). - Bit map: one hex digit is always exactly four bits, which is why hex is the usual shorthand for binary; the map lines them up so that is visible. It is drawn for values up to 64 bits. For a negative number it shows the magnitude until two's complement is ticked, then the stored bit pattern.
- In fixed-width storage: for each width, the value as an unsigned integer and the same bits read as a signed one. A reading in amber differs from the number you typed:
0xCAFEBABEis 3405691582 unsigned but -889275714 as a signed 32-bit integer, the classic overflow surprise. "Does not fit" means the value needs more bits than that width has. - Show as two's complement and Bit width: see the FAQ. Only affects negative numbers; positive numbers look the same either way.
- Load sample inserts
0xCAFEBABE; Clear empties the box.
Edge cases and common errors
- Digits that don't fit the base.
12read as binary stops with "That is not a valid binary (0-1) number". A binary number can only contain 0 and 1. - Empty input stops with "Enter a number" rather than showing four blank results.
- Thousands separators and underscores are tolerated:
1,000,000and1_000_000both parse as one million, matching how many languages let you write a large literal. - Values beyond 253 convert exactly: see the FAQ; this is the one place a naive base-converter built on plain numbers would quietly give the wrong answer.
- Two's complement out of range: see the FAQ.
- The prefix is always included in the copied value (
0x,0b,0o); if your target expects bare digits, just drop the first two characters after copying.
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.