StringMash.com

Number base converter

Decimal, binary, octal and hex, with the working shown.

Conversion
3 characters
Updates as you type
Swap to go the other way

Show the steps
  1. 156 ÷ 2 = 78 remainder 0
  2. 78 ÷ 2 = 39 remainder 0
  3. 39 ÷ 2 = 19 remainder 1
  4. 19 ÷ 2 = 9 remainder 1
  5. 9 ÷ 2 = 4 remainder 1
  6. 4 ÷ 2 = 2 remainder 0
  7. 2 ÷ 2 = 1 remainder 0
  8. 1 ÷ 2 = 0 remainder 1
  9. Read the remainders from the bottom up: 10011100
Printable chart

Using the converter

Pick the base you have and the base you want, then type the number. Several numbers can go in at once, separated by spaces, commas or new lines. Prefixes like 0x and 0b are fine, and so is the _ character used to group digits, as in 1001_1100. Numbers can be as long as you like and can be negative, but they have to be whole: there's no decimal point.

Show the steps opens the working under the answer, line by line, the same way you'd set it out on paper. It shows the first four numbers when there are several.

THE FIRST 33 NUMBERS

Decimal, binary, octal and hex from 0 to 32

DecimalBinaryOctalHex
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010
17100012111
18100102212
19100112313
20101002414
21101012515
22101102616
23101112717
24110003018
25110013119
2611010321A
2711011331B
2811100341C
2911101351D
3011110361E
3111111371F
321000004020

Decimal to another base: divide and keep the remainders

Divide the number by the base you're converting to, and write down the remainder. Divide the answer by the base again, and keep going until the answer is 0. The remainders, read from the last one back up to the first, are the digits of the new number.

For 13 in binary: 13 ÷ 2 is 6 remainder 1, 6 ÷ 2 is 3 remainder 0, 3 ÷ 2 is 1 remainder 1, and 1 ÷ 2 is 0 remainder 1. Reading up from the bottom gives 1101.

Hex works the same way, dividing by 16. A remainder from 10 to 15 is written as a letter, A to F, so 255 ÷ 16 is 15 remainder 15, and both 15s become F, giving FF.

Another base to decimal: add up the place values

In decimal the digits count ones, tens, hundreds and so on, each place worth ten times the one to its right. Other bases work the same way with a different multiplier. In binary each place is worth twice the one to its right, so the places are 1, 2, 4, 8, 16 and so on. In hex they're 1, 16, 256, 4096.

To convert, multiply each digit by its place value and add the results. 1101 in binary is 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1, which is 13. 1F in hex is 1 × 16 + 15 × 1, which is 31, because F stands for 15.

Binary to hex and octal: group the bits

Hex and binary line up neatly because 16 is 2 × 2 × 2 × 2. Every hex digit stands for exactly four bits, so there's no division to do. Split the binary into groups of four from the right, and swap each group for its hex digit. So 1001 1100 is 9C.

Octal does the same with groups of three, since 8 is 2 × 2 × 2. This is why programmers read binary in hex: two hex digits describe a byte exactly.

Questions

What is a number base?

It's how many digits a number system uses before it has to carry into the next place. Decimal is base 10, with the digits 0 to 9. Binary is base 2, octal base 8 and hexadecimal base 16.

Why does hexadecimal use letters?

It needs sixteen digits, and there are only ten numerals. The letters A to F stand for 10 to 15.

Can it convert fractions or decimals like 3.5?

No, only whole numbers. Fractions in other bases need a different method, multiplying rather than dividing, and most don't come out exactly.