Number base converter

Enter a number and choose its base. You get binary, octal, decimal and hexadecimal at once, plus any base up to 36. Very large numbers stay exact.

Two's complement

WidthBinaryHexSigned / unsigned

How to use the number base converter

  1. Type a whole number into Number. A leading minus sign, underscores and spaces are allowed, and so is a 0x, 0b or 0o prefix that matches the chosen base.
  2. Choose its base in It is in: decimal, binary, octal, hexadecimal or base 36.
  3. Read the binary, octal, decimal and hexadecimal results, plus the extra base you pick in Also show (any base from 2 to 36). Each row has a Copy button.
  4. Tick Group digits to split binary into fours, hex into pairs and decimal into thousands.
  5. Check the Two's complement table to see how the value is stored in 8, 16, 32 and 64 bits, read both as signed and unsigned.

How base conversion works

Each position in a number is worth the base raised to a power. In binary, 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 11. In hexadecimal, digits go 0–9 then A–F, so FF = 15×16 + 15 = 255.

The rightmost digit is worth base0 = 1, the next base1, then base2, and so on. Octal 755 is 7×64 + 5×8 + 5×1 = 493. Bases above 10 borrow letters, which is why base 36 is the highest: 0–9 plus A–Z gives 36 digits, and ZZ in base 36 is 35×36 + 35 = 1,295.

DecimalBinaryOctalHex
0000
81000108
10101012A
15111117F
16100002010
25511111111377FF
1024100000000002000400

Worked example: decimal to hex by hand

Divide by the target base repeatedly and read the remainders from last to first. For 3054 in hex:

3054 ÷ 16 = 190  remainder 14  (E)
 190 ÷ 16 =  11  remainder 14  (E)
  11 ÷ 16 =   0  remainder 11  (B)
                 read upward:  BEE

Type 3054 with Decimal selected and the converter shows hex BEE, binary 101111101110 and octal 5756, and notes that the value needs 12 bits.

Shortcuts between binary, octal and hex

Because 16 = 24 and 8 = 23, each hex digit is exactly four bits and each octal digit exactly three. To convert binary to hex, group bits in fours from the right: 1011 1110 1110 is B, E, E. That is why hex is the usual shorthand for bytes: one byte is always two hex digits, from 00 to FF. Octal survives mainly in Unix file permissions, where 755 is the bits 111 101 101, or rwx r-x r-x.

Negative numbers and two's complement

Computers store signed integers in two's complement: invert every bit of the positive value and add 1. In 8 bits, −1 is 11111111 (0xFF) and −128 is 10000000. The table shows how your number is stored at 8, 16, 32 and 64 bits, and what the same bits mean when read as unsigned.

For example, −42 in 8 bits: 42 is 00101010, inverted it is 11010101, and adding 1 gives 11010110, or 0xD6. Read as unsigned, those same bits are 214. An n-bit signed integer holds −2n−1 to 2n−1 − 1, so an 8-bit value runs from −128 to 127. The table shows Does not fit for widths too small for your number.

The main results show a negative number with a minus sign, as in -101010; only the two's complement table shows the stored bit pattern.

Prefixes 0x, 0b and 0o and separators like 1111_0000 are accepted.

Common mistakes

Edge cases

Only whole numbers are supported; a decimal point is reported as an invalid digit. Letters are case-insensitive on input and shown in uppercase. Values wider than 64 bits convert exactly between bases, but the two's complement table shows Does not fit for every width.

Key terms

Binary
Base 2, the number system computers use internally, written with only the digits 0 and 1. Each position is worth twice the one to its right, so binary 1011 is 8 + 0 + 2 + 1 = 11 in decimal.
Octal
Base 8, written with the digits 0 to 7. Each octal digit is exactly three bits, which is why it is still used for Unix file permissions such as 755. Many languages mark octal literals with a 0o prefix.
Hexadecimal
Base 16, written with the digits 0 to 9 and the letters A to F for 10 to 15. Each hex digit is exactly four bits, so one byte is always two hex digits. It is usually marked with a 0x prefix or a # in colors.
Radix
Another word for the base of a number system: the number of distinct digits it uses and the multiplier between neighboring positions. Decimal has radix 10, binary radix 2. Functions such as parseInt take a radix argument.
Place value
The worth of a digit's position in a number: the base raised to the power of the position, counting from 0 on the right. In decimal 352 the 3 is worth 3 × 10², or 300; in hex the same position is worth 16², or 256.
Two's complement
The standard way computers store signed integers. A negative number is formed by inverting every bit of its positive value and adding 1, so in 8 bits −1 is 11111111. The top bit then acts as the sign bit.
Bit
A binary digit, 0 or 1, the smallest unit of data. Eight bits make a byte, which can hold 256 different values. An n-bit unsigned integer ranges from 0 to 2ⁿ − 1.
Signed integer
A whole number type that can hold negative values, usually stored in two's complement. An n-bit signed integer ranges from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1, so a signed byte holds −128 to 127, while an unsigned byte holds 0 to 255.

Frequently asked questions

How do I convert binary to decimal?
Choose Binary in 'It is in' and type the digits. The decimal value appears straight away, with hex and octal.
How do I convert decimal to hex?
Type the decimal number with Decimal selected; the hexadecimal value is in the table. 255 is FF, 4096 is 1000.
Is there a size limit?
No practical one: the converter uses arbitrary-precision integers, so 100-digit numbers convert exactly.
Does it handle fractions?
No, whole numbers only. A decimal point is reported as an invalid digit. Fractions often have no exact form in another base: 0.1 in decimal repeats forever in binary, which is why floating-point arithmetic gives results like 0.1 + 0.2 = 0.30000000000000004.
How do I convert hex to binary?
Replace each hex digit with its four-bit binary pattern: 0 is 0000, 9 is 1001, A is 1010 and F is 1111. So 2F becomes 0010 1111, or 101111 without the leading zeros. Select Hexadecimal in 'It is in', type the value, and tick Group digits to see the bits in fours.
What is two's complement?
It is how almost all computers store negative integers. To negate a number, invert every bit and add 1, so −1 is all ones. The same addition circuit then works for positive and negative values, and there is only one zero. The highest bit acts as the sign: 1 means negative.
Why does 255 show as −1 in the 8-bit row?
The bits 11111111 mean 255 when read as an unsigned byte and −1 when read as a signed byte in two's complement. The table shows both readings, signed then unsigned. Which one is right depends on the type your program uses, such as uint8 versus int8.
What is base 36 used for?
Base 36 uses all ten digits and 26 letters, so it writes large numbers in few characters using only letters and digits. It is common in short IDs and URL slugs, for example from JavaScript's toString(36). The number 1,295 is ZZ, and 2,176,782,335 is ZZZZZZ.