How the conversion works
You choose the base the value is written in, and the page shows the same number in binary (base 2), octal (base 8), decimal (base 10), hexadecimal (base 16) and base 36. The input base list offers the same five bases. Internally it reads each digit left to right, multiplying a running total by the base and adding the digit, using JavaScript BigInt. It then prints that integer in each of the five bases. Since BigInt has no 64-bit limit, nothing is rounded; 18446744073709551616 (2 to the power of 64) converts exactly to 10000000000000000 in hex.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 10 | 1010 | 12 | a |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | ff |
| 256 | 100000000 | 400 | 100 |
| 1024 | 10000000000 | 2000 | 400 |
Worked example
Entering 255 with the input base set to decimal gives 0b11111111, 0o377, 255, 0xff and 73 in base 36 (7 x 36 + 3). Check by hand: 255 = 15 x 16 + 15, and 15 is f, so hex is ff. Each hex digit is exactly four bits, which is why ff is eight ones in binary. That 4-bit link is why programmers use hex as shorthand for binary: a byte is always two hex digits.
Input rules and pitfalls
- Output prefixes. Results are shown with
0b,0oand0xin front (decimal and base 36 have none), and the Copy button copies the prefix and any minus sign as well. Letters are lower-case. Base 36 uses the digits 0 to 9 and the letters a to z, which is how many short IDs and URL codes are written. - Underscores are ignored, so
1111_1111in binary reads as 255. Surrounding whitespace is trimmed. - A prefix is stripped only when it matches the input base. In binary mode a leading
0bis dropped, in octal mode0o, and in hexadecimal mode0x. In any other combination the characters are read as digits, so in hexadecimal mode0b11is the hex number 0xb11 (2833 in decimal), and in decimal mode it is rejected becausebis not a decimal digit. - Invalid digits are named in the error, such as "2" is not a valid digit for base 2.
- Negative numbers use a sign, not two's complement. A leading
-(or+) is accepted, and the result is the same magnitude with a minus sign in every base:-ffin hex gives-255in decimal and-0b11111111in binary. For a fixed-width two's-complement bit pattern, such as11111111for -1 in 8 bits, you still need to pick a word size yourself. - Whole numbers only. Fractions such as
0.5are not converted.
To turn letters into their numeric codes rather than convert numbers, use text to ASCII or binary to text. For file sizes in KB versus KiB, see the data storage converter, and for non-positional numerals, the Roman numeral converter.