Decimal to Binary Converter
Type any decimal number to get its binary value, with the division steps shown.
- Free
- Shows the steps
- Negative & decimal fractions
To convert decimal to binary, type a number in the box above. It works as a number to binary converter for whole numbers, fractions and negatives, and as a decimal to binary calculator that shows every step, so you can check your own work. Below: the method by hand, a 0–32 table, fractions, negatives and code. For several bases at once, try our binary number converter. Going the other way? Use binary to decimal. Want letters, not numbers? That’s text to binary.
How to convert decimal to binary
To convert a decimal number to binary, divide it by 2 repeatedly and write down each remainder (0 or 1). Stop when the quotient reaches 0, then read the remainders from last to first. For example, 13 gives remainders 1, 0, 1, 1, so 13 in binary is 1101.
Three steps, and the same three work for any whole number:
- Divide by 2. Write down the quotient and the remainder. The remainder is always 0 or 1.
- Repeat with the quotient. Keep going until the quotient is 0. Stopping at 1 loses the leftmost digit.
- Read the remainders from bottom to top. The first remainder is the 1s place. The last one is the biggest place, so it goes on the left.
Why does it work? Each division asks one question: is the number odd or even? Odd leaves a remainder of 1, which means there’s a 1 in the 1s place. The rest gets halved, and the same question now covers the 2s place, then the 4s. The remainders come out smallest place first, which is why you read them back upward.
Worked example: 156 to binary
156 is a good one to try. It fits in a byte and has a mix of 0s and 1s, so it shows the whole method.
| Division | Quotient | Remainder |
|---|---|---|
| 156 ÷ 2 | 78 | 0 |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Read the remainders upward: 10011100. Check it by adding the places that hold a 1: 128 + 16 + 8 + 4 = 156. That’s 8 bits, so 156 fits in one byte.
For a shorter run, 13 takes four divisions. The remainders are 1, 0, 1, 1, and read upward they give 1101.
The other method: subtract powers of 2
Division is the one most people are taught. Below 256 there’s a faster way to do it in your head. List the place values, 128, 64, 32, 16, 8, 4, 2, 1, and ask from left to right whether each one fits into what’s left. If it does, write 1 and subtract it. If not, write 0.
For 156: 128 fits (1), 28 left. 64 doesn’t (0). 32 doesn’t (0). 16 fits (1), 12 left. 8 fits (1), 4 left. 4 fits (1), 0 left. 2 and 1 don’t fit (0, 0). That’s 10011100, the same answer as before.
Division wins once numbers get big, because you don’t need a list of place values. Either way you’re repeating one rule until nothing is left, which is as close to a formula as this conversion gets.
Decimal to binary table: 0 to 32
Small numbers come up constantly, so here’s the whole run from 0 to 32. Every time you pass a power of 2 (2, 4, 8, 16, 32) the binary number gains a digit.
| Decimal | Binary |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 10 |
| 3 | 11 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
| 16 | 10000 |
| 17 | 10001 |
| 18 | 10010 |
| 19 | 10011 |
| 20 | 10100 |
| 21 | 10101 |
| 22 | 10110 |
| 23 | 10111 |
| 24 | 11000 |
| 25 | 11001 |
| 26 | 11010 |
| 27 | 11011 |
| 28 | 11100 |
| 29 | 11101 |
| 30 | 11110 |
| 31 | 11111 |
| 32 | 100000 |
Decimal to binary table, 0–32. The next few worth knowing: 64 is 1000000, 128 is 10000000, 255 is 11111111 and 256 is 100000000.
For every value from 0 to 255 with hex and octal beside it, see the binary numbers chart.
Numbers people look up most
Tap a number to open it in the converter.
Convert a decimal fraction to binary
A decimal fraction takes two passes. Convert the whole part with the division method above. Then convert the fraction by multiplying by 2.
Multiply the fraction by 2. The digit in front of the decimal point (0 or 1) is your next binary digit. Drop it, keep what’s left, and multiply again. Stop when you reach 0. Read the digits in the order you got them, after the radix point, which is the binary version of the decimal point.
Take 0.625:
- 0.625 × 2 = 1.25, so the digit is 1. Keep 0.25.
- 0.25 × 2 = 0.5, so the digit is 0. Keep 0.5.
- 0.5 × 2 = 1.0, so the digit is 1. Nothing left, so stop.
That makes 0.625 equal to 0.101. Add a whole part and you have 13.625, which is 1101 for the 13 and .101 for the rest: 1101.101.
Some fractions never reach 0. Try 0.1 and the digits run 0, 0, 0, 1, 1, 0, 0, 1, 1, and keep going. It’s 0.0(0011), with the bracketed block repeating forever. The reason: 0.1 is 1/10, and 10 has a factor of 5 that isn’t a power of 2. Only fractions whose denominator is a power of 2 (0.5, 0.25, 0.375, 0.625) end cleanly. Everything else gets cut off after some number of bits, and that’s why a computer stores 0.1 as a close neighbour, not the exact value.
Negative numbers in binary
Binary hardware has no minus sign. Computers store negatives as two’s complement. Take −13 in 8 bits: write 13 as 00001101, flip every bit to get 11110010, then add 1. The result is 11110011.
Pick a bit width in the converter above and it does this for you, and it warns you when the number doesn’t fit.
Decimal to binary in Python, JavaScript and Excel
Most languages have a built-in for this, so you rarely write the division loop yourself. In Python, bin() adds a 0b prefix and format() doesn’t. Use '08b' to pad to 8 digits.
| Language | Code | Result for 13 |
|---|---|---|
| Python | bin(13) | '0b1101' |
| Python | format(13, 'b') | '1101' |
| Python | format(13, '08b') | '00001101' |
| JavaScript | (13).toString(2) | "1101" |
| Excel | =DEC2BIN(9, 4) | 1001 |
Excel’s DEC2BIN only takes whole numbers from −512 to 511, and it returns negatives as 10-bit two’s complement: =DEC2BIN(-100) gives 1110011100.
Common mistakes
- Reading the remainders top to bottom. You get the number backwards. 13 would come out as 1011, which is 11.
- Stopping at a quotient of 1. The last division, 1 ÷ 2, still gives a remainder of 1. That’s your leftmost digit.
- Dropping leading zeros when a width is asked for. 13 is 1101, but in 8 bits it’s 00001101.
Frequently asked questions
How do you convert decimal to binary?
Divide the number by 2 repeatedly and write down each remainder. Stop when the quotient is 0, then read the remainders from last to first. For 13 that gives 1101.
How do you convert a decimal fraction to binary?
Convert the whole part by division. Then multiply the fraction by 2 again and again, taking the whole-number digit each time. 0.625 becomes 0.101.
Why does 0.1 repeat in binary?
0.1 is 1/10, and 10 has a factor of 5 that isn’t a power of 2, so the binary expansion never ends. It comes out as 0.0(0011), with the block 0011 repeating.
How are negative numbers written in binary?
As two’s complement. In 8 bits, −13 is 11110011.
How many bits do I need for a number?
As many as its binary form has. 156 needs 8 and 1,000 needs 10. One byte holds 0 to 255, and 256 needs a ninth bit.
What is 255 in binary?
11111111, the largest value that fits in 8 bits. 256 is 100000000.
How do I convert a large decimal number to binary?
The method is the same, so use the converter. 1,024 is 10000000000 and 65,535 is 1111111111111111.
How do I check my answer?
Convert it back. Add the place values of the 1s: 10011100 is 128 + 16 + 8 + 4, which is 156. Or press the Swap button.
Sources: Knuth, The Art of Computer Programming, Vol. 2, §4.1 (radix conversion) · Python docs: bin() · Python docs: format() · Microsoft Support, DEC2BIN function
