Unit & number converters

Number base converter

Type a number in any base from 2 to 36 and see it in binary, octal, decimal and hexadecimal at once. Integers of any length stay exact, and the bit views show two's complement and floating-point encodings.

Binary (base 2)
Octal (base 8)
Decimal (base 10)
Hexadecimal (base 16)

Two's complement (signed integers)

IEEE 754 floating point

Runs entirely in your browser. Nothing you enter here is uploaded.

How to convert between bases

  1. Type the number and choose the base it is written in. Prefixes are understood: 0x for hexadecimal, 0b for binary, 0o for octal. Underscores and spaces used as digit separators are ignored, and a leading minus sign is allowed.
  2. Read the same value in binary, octal, decimal and hexadecimal. Long results are grouped — binary and hex in fours, decimal in thousands — and the copy buttons copy the digits without the grouping.
  3. Pick any other base from 2 to 36 in the last row.
  4. Below, see how the integer is stored as an 8-, 16-, 32- or 64-bit signed value, and type a decimal number to see its single- and double-precision floating-point bits.

Positional notation

In base b, each digit position is worth b times the one to its right. The binary number 1011 is 1×8 + 0×4 + 1×2 + 1×1 = 11. Bases above 10 need more digit symbols, so letters continue after 9: A is 10, F is 15, Z is 35. That is why 36 is the largest base with conventional digits, and why the hexadecimal FF is 15×16 + 15 = 255.

Most online converters use JavaScript's ordinary numbers, which are 64-bit floating point and silently lose precision above 2^53 (9,007,199,254,740,992). This converter uses arbitrary-precision integers (BigInt), so 2^64 — 18446744073709551616 — converts to hexadecimal 10000000000000000 exactly, and so do numbers hundreds of digits long.

Two's complement

Computers store signed integers in two's complement. For an n-bit type, non-negative numbers are written normally, and a negative number −x is stored as 2^n − x. In 8 bits, −1 becomes 11111111 and −128 becomes 10000000; the range is −128 to 127. The top bit therefore acts as the sign. The table shows the pattern for each common width, or says the value does not fit.

IEEE 754 floating point

Decimal fractions are stored in binary floating point: a sign bit, an exponent and a fraction (8 and 23 bits in single precision, 11 and 52 in double). Many decimal fractions have no exact binary form, just as 1/3 has none in decimal. 0.1 in double precision is stored as the hexadecimal pattern 3FB999999999999A, which is very slightly more than 0.1; in single precision it is 3DCCCCCD, which is 0.10000000149011612. This is why 0.1 + 0.2 does not equal exactly 0.3 in most programming languages.

Examples

InputResult
255 (decimal)11111111 binary, 377 octal, FF hex
0b1010_1010 (binary)170 decimal
0x1F (hex)31 decimal
zz (base 36)1295 decimal
-1010 (binary)-10 decimal
18446744073709551616 (decimal, 2^64)10000000000000000 hex, exactly
−1 as 8-bit two's complement11111111
128 as 8-bit signeddoes not fit (range −128 to 127)
0.1 as a 64-bit float3FB999999999999A
−2.5 as a 64-bit floatC004000000000000

Invalid input is pinpointed: in base 10, 12a fails at character 3; in binary, 102 fails at character 3 because 2 is not a binary digit.

Limits

  • Integers only for base conversion. Fractions such as 0.1 in binary are infinite repeating patterns; use the floating-point section to see how a fractional value is actually stored.
  • Bases 2 to 36. Base 64 is an encoding for bytes rather than a numeral system; use the Base64 tool for that.
  • Letters are case-insensitive, so base-36 input cannot distinguish a from A.

Frequently asked questions

How do I convert decimal to binary?

Type the decimal number with the base set to decimal. The binary form appears immediately, grouped in fours for readability.

Why is 0xFF equal to 255?

F is 15, and the left digit is worth 16 times the right one: 15 × 16 + 15 = 255.

Can it handle very large numbers?

Yes. Conversion uses arbitrary-precision integers, so there is no upper limit and no rounding.

What is two's complement?

The way computers store negative integers: in n bits, −x is stored as 2^n − x, so −1 in 8 bits is 11111111.

Why is 0.1 not exact in binary?

Because 1/10 has no finite binary expansion. The float section shows the nearest value that can actually be stored.

Sources and further reading

↵ to open · Esc to close