Skip to content
Developer tools

Number Base Converter

Type a number in any base and read it in binary, octal, decimal, hex and a base of your choice, with two's complement bit patterns for 8, 16, 32 and 64 bits.

Last checked

Number

Input base

Read as base 10 (auto). 8 bits.

In every base

  • Binary base 21111 1111
  • Octal base 8377
  • Decimal base 10255
  • Hexadecimal base 16FF

Two’s complement

Bits
1111 1111
Hex
0xFF
Signed (int8)
-1
Unsigned (uint8)
255

How to use it

  1. Type a number. Auto reads 0x, 0b and 0o prefixes and hex letters; or pick the input base.
  2. Read the number in every base below and copy the one you need (with its prefix).
  3. For a negative number or a register value, pick a bit width to see its two's complement form.

What it checks and why

A base, or radix, is how many digits a number system uses. Decimal uses ten. Binary uses two and is how computers store numbers. Hexadecimal uses sixteen (0 to 9 and a to f): each hex digit is exactly four bits, so it is the short way to write bytes, colours (#ff8800) and memory addresses. Octal uses eight and still appears in Unix file permissions such as 755.

To convert, the tool reads each digit, multiplies the running total by the base and adds the digit, then writes the total out in the other bases. It does this with JavaScript BigInt, so there is no 2^53 limit like with ordinary numbers and a 40-digit value converts exactly.

Computers store negative integers in two's complement: in n bits, a negative number x is stored as 2^n + x. In 8 bits, -1 is 11111111 (0xFF) and -128 is 10000000. The same bits read as unsigned are 255 and 128, which is why one pattern can mean two numbers. The two's complement panel shows both readings for 8, 16, 32 and 64 bits.

Specs and sources

Limits

  • Whole numbers only; fractions such as 0.1 in binary are not converted.
  • Bases above 36 (such as Base64 or Base58) need their own alphabets and are not covered.
  • Two's complement is shown up to 64 bits.

Questions

How do I convert binary to decimal?
Multiply each bit by its power of two and add them up. 1011 is 1×8 + 0×4 + 1×2 + 1×1 = 11. Type 0b1011 or pick Bin and the tool shows 11.
How do I convert decimal to hexadecimal?
Divide by 16 repeatedly and write the remainders from last to first, using a to f for 10 to 15. 255 is 15 remainder 15, so FF.
What is 0xFF in decimal?
255. FF is 15×16 + 15. It is the largest value of one byte, eight bits all set to 1.
How are negative numbers written in binary?
With two's complement: invert all the bits of the positive number and add one. In 8 bits, 5 is 00000101 and -5 is 11111011.
Why does JavaScript give the wrong result for big numbers?
Ordinary numbers are 64-bit floats and are exact only up to 2^53 - 1 (9,007,199,254,740,991). Use BigInt (123n or BigInt("123")) for larger integers; this tool does.
What does the 0x prefix mean?
It marks a hexadecimal literal in C, JavaScript, Python and most other languages. 0b marks binary and 0o marks octal.