Number base converter (binary, decimal, hex)

Every base writes the same number with a different set of digits: 255 in decimal is 11111111 in binary, 377 in octal and FF in hexadecimal. Type a number in any base from 2 to 36 to see it in all the others, exactly, up to 10,000 digits long.

Whole numbers, as large as you like, with an optional minus sign. 0x, 0b and 0o prefixes work; spaces and underscores between digits are ignored.

In hexadecimal

FF

255 decimal · 11111111 binary

Binary (base 2)
11111111grouped: 1111 1111
Octal (base 8)
3770o377
Decimal (base 10)
255
Hexadecimal, uppercase
FF0xFF
Hexadecimal, lowercase
ff0xff
Base 36
73digits 0–9 then a–z, as JavaScript's toString(36) writes them
Binary digits
8 bits
Bytes needed
1 byte
Smallest unsigned type
8-bit (uint8, 0 to 255)
Smallest signed type
16-bit (int16, -32,768 to 32,767)

How do you convert a number from one base to another?

Each digit is worth its value times a power of the base, counted from 0 at the right. In decimal, 255 is 2 × 100 + 5 × 10 + 5 × 1; in hexadecimal, FF is 15 × 16 + 15 × 1, which is also 255; in binary, 11111111 is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1. Bases above 10 borrow letters for the extra digits, so A is 10, F is 15 and Z is 35, which is why base 36 is the largest that fits 0–9 and A–Z.

To write a number in another base, divide it by that base again and again and read the remainders from last to first. 255 ÷ 16 is 15 remainder 15, and 15 ÷ 16 is 0 remainder 15, giving F and F: FF. Binary, octal and hex also map straight onto each other, because one hex digit is exactly four bits and one octal digit exactly three.

JavaScript's regular numbers can only hold whole numbers exactly up to 9,007,199,254,740,991 (2^53 − 1); above that, neighbouring integers round to the same value. This converter uses BigInt instead, so every digit of a large number is exact. Negative numbers keep their minus sign in every base, as JavaScript's toString does, and the result also shows the two's complement bit pattern that a fixed-width signed integer stores.

value = dₙ × baseⁿ + … + d₂ × base² + d₁ × base + d₀
FF₁₆ = 15 × 16 + 15 = 255₁₀
255 ÷ 16 = 15 r 15,  15 ÷ 16 = 0 r 15  →  FF

What are 0 to 16 and the powers of two in binary, octal and hex?

0 to 16, then powers of two up to 2³², in decimal, binary, octal and hexadecimal
DecimalBinaryOctalHex
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010
32 (2⁵)1000004020
64 (2⁶)100000010040
128 (2⁷)1000000020080
256 (2⁸)100000000400100
1,024 (2¹⁰)100000000002000400
4,096 (2¹²)1000000000000100001000
65,536 (2¹⁶)1000000000000000020000010000
4,294,967,296 (2³²)10000000000000000000000000000000040000000000100000000

How to convert a number between bases

  1. 1
    Type the numberEnter it as you have it: 255, FF, 0xFF, 1111_1111 or -42. Spaces and underscores between digits are ignored.
  2. 2
    Say which base it is inPick decimal, binary, octal or hexadecimal, or another base from 2 to 36. A 0x, 0b or 0o prefix is read for you.
  3. 3
    Read every base at onceThe result lists binary, octal, decimal, hex in both cases and base 36, plus any extra base you ask for, each with a copy button.
  4. 4
    Check its sizeSee how many bits and bytes it needs and the smallest unsigned and signed integer types it fits.

Frequently asked questions

How do I convert binary to decimal?
Add up the place values of the 1s, doubling from the right: 1, 2, 4, 8, 16 and so on. 1011 is 8 + 0 + 2 + 1 = 11, and 11111111 is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.
How do I convert decimal to hexadecimal by hand?
Divide by 16 repeatedly and write down each remainder, using A to F for 10 to 15, then read them from last to first. 255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15, so 255 is FF; 4,096 is 1000 in hex because it is 16³.
Why does JavaScript get large numbers wrong?
Its regular Number type holds whole numbers exactly only up to Number.MAX_SAFE_INTEGER, 9,007,199,254,740,991 (2^53 − 1). Above that, some integers can't be stored, so MAX_SAFE_INTEGER + 1 and + 2 compare equal. BigInt stores integers of any size exactly, which is what this converter uses.
What do 0x, 0b and 0o mean in front of a number?
They name the base in source code: 0x is hexadecimal, 0b is binary and 0o is octal, in either case, so 0xFF, 0b11111111 and 0o377 are all 255 in JavaScript. A plain leading 0, as in 0377, is an old octal form that JavaScript's strict mode rejects.
How are negative numbers written in binary?
On paper and in JavaScript's toString, with a minus sign: -10 is -1010. Inside a computer, fixed-width signed integers use two's complement, where -1 in 8 bits is 11111111 and -200 needs 16 bits, 1111111100111000. This converter shows both.

Sources

Related tools

See all 73 free tools

Need a custom dev tool for your team?

We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.

Built by CountryDevs · No signup · No ads · We count visits, never what you enter