What is a number base converter?
A number base (or radix) is how many distinct digits a numeral system uses. We write everyday numbers in base 10, with the digits 0 to 9. Computers work in base 2 (binary), where every digit is a 0 or a 1, and programmers constantly read the same value in base 8 (octal) and base 16 (hexadecimal) because those are compact ways to write groups of bits: one hex digit is exactly four bits, one octal digit is three.
You meet the other bases all the time. Hexadecimal is in memory addresses, colour codes, byte dumps and 0xFF-style literals in C, Java, JavaScript, Go and Rust. Octal is how Unix file permissions are written (755, 644). Binary shows up in bit masks, flags and hardware registers. Converting by hand is slow and easy to get wrong, especially with a long number.
This integer base converter takes a whole number in any base from 2 to 64 and shows it at once in binary, octal, decimal, hexadecimal, base 64 and one custom base of your choice. It uses arbitrary-precision integers, so a 20-digit number is converted exactly, not rounded like a normal JavaScript number. It runs in your browser: nothing you type is sent anywhere.
How to convert a number between bases
- Type or paste the number in the number field. The tool opens with
42already filled in so you can see every output straight away. - Set the input base to the base the number is written in. The default is 10; use 2 for binary, 8 for octal, 16 for hexadecimal.
- You can skip step 2 when the number carries a prefix.
0xand#mean hexadecimal,0omeans octal and0bmeans binary, and the Visual Basic forms&H,&Oand&Bwork too. A note tells you when the prefix overrode the input base. - Read the fixed outputs (binary, octal, decimal, hexadecimal, base 64) and copy the one you need.
- For any other base, change the custom base (2 to 64) and read the last row.
- Turn on uppercase letters for
FFinstead offf, and the prefix option for0b,0oand0xin front of binary, octal and hexadecimal results.
The input is cleaned first: spaces and underscores between digits are ignored (1_000_000 works), a leading - is kept as a sign, and the suffixes of C, Java and JavaScript literals (U, L, UL, LL, n) are removed for bases up to 18. Up to base 36 letter case does not matter; above 36 it does, because a and A are different digits.
Examples of base conversion
255 to hex, binary and octal
Input 255, input base 10.
| Base | Result |
|---|---|
| Binary | 11111111 |
| Octal | 377 |
| Hexadecimal | ff |
255 is the largest value of one byte.
Reading a hexadecimal literal with a prefix
Input 0xFF with the input base left at 10. The prefix wins, a note says base 16 was detected, and the decimal output is 255. With the prefix option on, binary is written 0b11111111 and octal 0o377.
Negative numbers and C-style literals
Input -42 gives binary -101010 and hexadecimal -2a: the sign stays in front, it is not two's complement. Input 1_000UL is read as 1000 and gives hexadecimal 3e8.
A number too big for a normal integer
Input 12345678901234567890 in base 10 gives hexadecimal ab54a98ceb1f0ad2 and binary 1010101101010100101010011000110011101011000111110000101011010010. Every digit is exact.
Base 36 and base 64 digits
Input zz with input base 36 gives decimal 1295. In the base 64 row, decimal 255 is written 3/: the digits are 0-9, a-z, A-Z, + and / in that order. This is a number system, not Base64 encoding of bytes; for that use the Base64 tool.
Common errors and how to fix them
- The digit "2" does not exist in base 2. (or "g" in base 16): the number has a character that is not a valid digit in the input base. Check the input base, or fix the digit. Letters beyond
fneed a base above 16. - The input base must be a whole number from 2 to 64. Bases such as 1 or 70 are refused, and the same message appears for the custom base.
- The result looks wrong for
1010. With the input base at 10 it is one thousand and ten. Set the input base to 2, or write0b1010. - A leading zero is not octal. In C
010means 8, but here010in base 10 is 10. Use0o10or set the input base to 8. - Fractions are not converted. Only integers work;
3.14is rejected as an invalid digit.
Frequently asked questions
How do I convert decimal to binary?
Type the decimal number with the input base at 10 and read the binary row. By hand, divide by 2 repeatedly and read the remainders from last to first: 13 gives 1101. To turn text into bits, see text to binary.
How do I convert hexadecimal to decimal?
Set the input base to 16 (or start the number with 0x) and read the decimal row. ff is 255 and 3e8 is 1000. Each hex digit is worth sixteen times the one to its right.
How many bits is a hex digit?
Exactly four. That is why two hex digits make one byte and why a colour such as #ff6347 is three bytes. To work with colours directly, use the colour converter.
What is the largest number this tool can convert?
It uses arbitrary-precision integers, so there is no fixed digit limit.
What is base 64 here, and is it Base64?
It is a positional number system with 64 digits, not the byte encoding. To encode bytes or files as text, use Base64; to convert IP addresses between notations, the IPv4 address converter.
How to convert number bases in code
JavaScript
parseInt and toString take a base from 2 to 36; for numbers beyond 2^53 use BigInt.
parseInt('ff', 16); // 255
(255).toString(2); // '11111111'
BigInt('12345678901234567890').toString(16); // 'ab54a98ceb1f0ad2'
BigInt('0b1010'); // 10nPython
int() reads any base from 2 to 36, and base 0 follows the prefix.
int('ff', 16) # 255
int('0b1010', 0) # 10
bin(255), oct(255), hex(255) # ('0b11111111', '0o377', '0xff')
format(255, '08b') # '11111111'Go
n, err := strconv.ParseInt("ff", 16, 64) // 255
if err != nil {
log.Fatal(err)
}
fmt.Println(strconv.FormatInt(n, 2)) // 11111111Bash
echo $((16#ff)) # 255
echo $((2#1010)) # 10
printf '%x\n' 255 # ff
printf '%o\n' 255 # 377