Number base converter

Type a number in any base and the others follow.

How it is converted

How positional notation works

In 156, the 1 is worth 100, the 5 is worth 50 and the 6 is worth 6: each place is worth ten times the place to its right. Every base works the same way with its own number. In binary each place is worth twice the next one, so 10011100 is 128 + 16 + 8 + 4 = 156. In hexadecimal each place is worth sixteen times the next, and the digits after 9 are letters, A = 10 to F = 15, so 9C is 9 × 16 + 12 = 156.

This converter works with any base from 2 to 36 (ten digits plus 26 letters) and with whole numbers of any size: they are kept exactly, digit for digit, even far beyond the 2⁵³ where ordinary JavaScript numbers start rounding. Type in any field and the others follow.

Reading the steps

Under the fields the tool works the conversion out. From decimal to another base it uses repeated division: divide by the base, keep the remainder, carry on with the quotient until it reaches 0. The remainders, read from the bottom up, are the digits. For 156 in binary:

156 ÷ 2 = 78   remainder 0
 78 ÷ 2 = 39   remainder 0
 39 ÷ 2 = 19   remainder 1
 19 ÷ 2 =  9   remainder 1
  9 ÷ 2 =  4   remainder 1
  4 ÷ 2 =  2   remainder 0
  2 ÷ 2 =  1   remainder 0
  1 ÷ 2 =  0   remainder 1
read upwards: 10011100

From another base to decimal it adds up the place values: each digit times the base raised to its position, counting from 0 at the right. For 9C in hexadecimal that is 9 × 16¹ + 12 × 16⁰ = 144 + 12 = 156.

Between binary and hexadecimal there is a shortcut, which the tool also shows: each hex digit is exactly four bits. 9 is 1001 and C is 1100, so 9C is 1001 1100. Octal works the same with three bits per digit: 234 in octal is 010 011 100.

The first sixteen numbers

DecimalBinaryHexadecimalOctal
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000810
91001911
101010A12
111011B13
121100C14
131101D15
141110E16
151111F17

Where each base is used

  • Binary: anything about individual bits, such as flags packed into one number or a network mask (255.255.255.0 is 24 ones followed by 8 zeros).
  • Hexadecimal: a short way to write bytes, two digits per byte. Web colours (#FF8800 is red 255, green 136, blue 0), memory addresses, hashes and Unicode code points (ñ is U+00F1) are all written in hex.
  • Octal: Unix file permissions, three bits per digit. In chmod 755, 7 = 111 = read, write and execute for the owner, and 5 = 101 = read and execute for everyone else.
  • Base 36: short identifiers made of digits and letters, because it packs the most into each character without needing upper and lower case.

In code, a prefix says which base a number is written in:

LanguageBinaryOctalHexadecimal
JavaScript, Python, Rust0b10100o120xA
C, C++, Java0b1010 (C23, C++14, Java 7)012 (a leading zero)0xA

This page accepts the 0b, 0o and 0x prefixes in their own fields, along with spaces and underscores between digits (1001_1100), a leading minus sign, and upper or lower case.

Negative numbers: two’s complement

A computer stores a signed integer in a fixed number of bits, and writes a negative number in two’s complement: take the positive number in binary, invert every bit, and add 1. For −5 in 8 bits: 5 is 00000101, inverted it is 11111010, plus 1 it is 11111011, or FB in hex. The top bit then counts as −128, so 8 bits hold −128 to 127.

The same pattern read as unsigned is 251, which is why a byte FF can be 255 or −1 depending on the type. The tool shows a number’s pattern in 8, 16, 32 or 64 bits with both readings, and the invert-and-add-one steps for a negative.

Common mistakes

  • A letter for a digit: the letter O for zero, or a lowercase l for one. The tool names the character it cannot read and where it is.
  • The leading-zero trap: in C, C++ and Java, and in old JavaScript, 010 is octal, so it means 8. Python 3 refuses it and asks for 0o10.
  • Fractions: this tool converts whole numbers. Fractions are a different problem: 0.1 has no exact binary form (it repeats forever: 0.000110011…), which is why 0.1 + 0.2 is not exactly 0.3 in most programming languages.
  • Too many digits for the type: 64 bits hold at most 18 446 744 073 709 551 615 unsigned. The signed view says when a number does not fit a width.

Questions

Why does the tool stop at base 36?

Because there are 36 single characters to write digits with: 0 to 9 and A to Z. Larger bases need other symbols, as Base64 does with its own 64-character alphabet.

How do I convert hexadecimal to binary without a calculator?

Replace each hex digit with its four bits from the table above and join them: 2F is 0010 1111. To go back, split the bits into groups of four from the right.

Why is FF shown as −1 in the signed view?

In 8 bits, 11111111 read as signed is −1: the top bit counts −128 and the other seven add up to 127. Pick a wider width and FF is 255 again, because the top bit is then 0.

Does the number I type leave my computer?

No. Every conversion and every step is computed in your browser.

More encoding and conversion tools

See all tools