Skip to main content
CalcMax

Decimal to Binary Converter

Result

10001

Binary

Place values
16 + 1

A decimal to binary converter rewrites a whole number from base ten into base two. The value does not change, only the notation does, and the method that gets you there is repeated division. Divide the number by two, keep the remainder, divide the quotient by two, and carry on until the quotient reaches zero. The remainders are the binary digits — but they come out in reverse, so the last remainder you write down is the first digit of the answer. Take 17: 17 ÷ 2 is 8 remainder 1, then 8 ÷ 2 is 4 remainder 0, then 4 ÷ 2 is 2 remainder 0, then 2 ÷ 2 is 1 remainder 0, and finally 1 ÷ 2 is 0 remainder 1. Read bottom to top, the remainders are 1, 0, 0, 0, 1, so 17 is written 10001 in binary. That reversal is where most of the mistakes happen, which is why the page prints every division rather than only the answer. A binary place value is a power of two, and reading the answer back as a sum of those place values is how you check the work: 10001 has a 16 and a 1 in it and nothing else, and 16 + 1 is 17 again. The direction matters just as much when the number gets shorter — a whole number that is a power of two like 16 comes out as a single one followed by zeros, and one that is one less than a power of two comes out as nothing but ones, so 15 is 1111 and 255 is 11111111.

Dividing 17 by two, one round at a time, until the quotient reaches zero

RoundDivisionQuotientRemainder
117 ÷ 281
28 ÷ 240
34 ÷ 220
42 ÷ 210
51 ÷ 201

This is the method rather than a result, which is why it is fixed at 17 while the panel above converts whatever you typed. Read the remainder column from the bottom up and the digits of the answer appear in order: 1, 0, 0, 0, 1, which is 10001. The reason the column has to be read upwards is that each division finds the least significant digit of what is left; the first round pins down the ones place, the second the twos place, and so on, so the rounds run right to left through the answer. The reason the process is allowed to stop when the quotient hits zero is that a quotient of zero means nothing above the current place is set. Two details worth noticing in the table: every remainder is 0 or 1 and can be nothing else, because the divisor is two; and the quotient shrinks by more than half each round, which is why the ladder for even the largest allowed input is only about fifty rows long. If you are converting a different number, follow the same four columns on paper — the table tells you what the columns are, not what your numbers will be.

Formula

17 ÷ 2 = 8 r 1 → 8 ÷ 2 = 4 r 0 → 4 ÷ 2 = 2 r 0 → 2 ÷ 2 = 1 r 0 → 1 ÷ 2 = 0 r 1 ⇒ 17 = 10001 = 16 + 1

17
The whole number to convert, written in base ten. It has to be a whole number: a decimal point or a thousands separator is refused rather than rounded away, because this family of pages works in whole numbers throughout
÷ 2
The step that repeats. Two is the base you are converting into, so each round asks how many twos fit — and the amount left over is exactly the digit that belongs in that position
quotient
The part that carries on to the next round. The process stops when the quotient reaches zero, and that is the sign that no higher place value is needed
remainder
The digit produced by that round. Dividing by two can only ever leave 0 or 1 behind, which is why the answer comes out as binary digits and not as some other set of symbols
⇒ 10001
The digits assembled from the bottom up. The first remainder found is the rightmost digit and the last one found is the leftmost, which is the one step of this method that is easy to get backwards
16 + 1
The answer read back as binary place values: 10001 has ones in the sixteen and one positions only, so adding those gives 17 again. This is the check the page prints, and it works because the sum of the place values of a binary number is the number
53 bits
How long the answer may be: fifty-three binary digits, which is 9007199254740991 in decimal. Past that width a machine cannot hold neighbouring whole numbers apart, so a larger input is refused instead of being converted to something that only looks right

Writing a number in base two comes up whenever a machine's own notation has to be produced by hand. Packing several small values into one integer means working out which bits each value occupies, and that starts with the value in binary: a colour channel, a set of permission flags, a bit field in a configuration register. Anyone reading a datasheet meets the same task from the other side, because the ranges and masks printed there are written in hexadecimal or binary and the number they came from is decimal. In coursework the direction is usually asked for directly — convert decimal to binary and show the working — and the printed ladder is exactly that working, one line per division. The same conversion answers questions that do not look like conversions: how many bits does a value of this size need, which power of two is just above it, and why an 8-bit field runs from 0 to 255 and not to 256. Programmers doing it in their head usually reach for the powers of two instead of the ladder, subtracting the largest power that fits and repeating, which this page's output supports as well: each subtraction that succeeds leaves a 1 in that position, and the place value sum printed beside the answer is those ones added back up.

Worked examples

  1. Writing 17 in binary

    1. 17 ÷ 2 = 8, remainder 1 — write down the 1
    2. 8 ÷ 2 = 4, remainder 0
    3. 4 ÷ 2 = 2, remainder 0
    4. 2 ÷ 2 = 1, remainder 0
    5. 1 ÷ 2 = 0, remainder 1 — the quotient has reached zero, so stop
    6. Read the remainders from the bottom up: 1, 0, 0, 0, 1, which is 10001

    The default, and the one that shows the reversal: the first remainder found is the last digit of the answer. Reading the remainders in the order they were produced gives 10001 backwards — 10001 reversed is 10001 here only by luck, so the next example is the one to check the rule on. Verifying it: 16 + 1 = 17.

  2. Writing a full byte, 255

    1. 255 ÷ 2 = 127, remainder 1
    2. 127 ÷ 2 = 63, remainder 1 — and every round after this leaves 1 as well
    3. 63 → 31 → 15 → 7 → 3 → 1, each with remainder 1
    4. 1 ÷ 2 = 0, remainder 1 — eight rounds in all
    5. Eight remainders of 1, read bottom up: 11111111

    255 is the largest value an eight-bit field can hold, and this is why: eight binary digits give 2⁸ combinations, and the largest is 11111111. The other end of the same fact is that 256 is 100000000 — nine digits — which is the number that does not fit in a byte. The place value sum is the whole ruler added up, and it is worth seeing once in full.

  3. A power of two, 16

    1. 16 ÷ 2 = 8, remainder 0
    2. 8 ÷ 2 = 4, remainder 0
    3. 4 ÷ 2 = 2, remainder 0
    4. 2 ÷ 2 = 1, remainder 0
    5. 1 ÷ 2 = 0, remainder 1
    6. Read bottom up: one 1 followed by four 0s, which is 10000

    A power of two produces exactly one remainder of 1 and then stops, so the place value sum collapses to a single term. This is the shape to recognise: any number that is a power of two is a single one followed by zeros in binary, which is why powers of two are the natural unit for field widths, page sizes and buffer capacities.

  4. Leading zeros do not change the value

    1. The leading zeros in the input sit at the front of the decimal number and add nothing
    2. The conversion is done on 17, exactly as in the first example
    3. Both outputs come out word for word the same as they did there

    Leading zeros are accepted on the input side because a decimal number is often pasted from somewhere that padded it, and they change nothing: zero hundreds is still zero hundreds. The same is true in the other direction, where a value is padded out to a fixed width on purpose — 00010001 in an eight-bit field is the same number as 10001, and the page accepts either.

Limitations

This page converts whole numbers only. A decimal point is rejected rather than rounded, so 17.5 cannot be converted — a fractional reading would need a second rule about how many digits to show and how to round the last one, and every page in this group draws that line in the same place. Thousands separators are refused too, so write 1500 rather than 1,500; the comma is read as a decimal point in some languages, and guessing between the two readings is worse than asking. The input may be at most 9007199254740991, which is fifty-three binary digits; a larger value cannot be held exactly by a machine and is refused with a message instead of being converted to something that looks like an answer. Leading zeros and a leading minus sign are both accepted. The page prints the halving ladder for 17 in the table below, which is fixed and does not follow the number you typed — the panel answers your number, the table shows the method. The opposite direction, reading a binary number back as decimal, is a separate page, and this one does no arithmetic on the result.

Frequently asked questions

How do I convert a decimal number to binary by hand?
Divide by two, write down the remainder, then divide the quotient by two and repeat until the quotient is zero. For 17 that gives remainders 1, 0, 0, 0, 1 — and because each round produces the next digit from the right, you read them from the bottom up to get 10001. The alternative that many people find quicker is to subtract the largest power of two that fits, mark a 1 in that position, and repeat with what is left; both give the same digits, and the place value sum printed on this page is what the second method leaves behind.
Why do I read the remainders from the bottom up?
Because the first division answers a question about the smallest place, not the largest. Dividing 17 by two asks how many twos are in it and what is left over — and what is left over is the ones digit, because it is the part that could not make a two. The next round asks the same question about the twos, and what it leaves over is the twos digit. The rounds therefore walk from the rightmost digit to the leftmost, and reading them in the order they were written gives the answer reversed.
Can I convert a decimal number with a fractional part?
Not here. This page takes whole numbers, so 17.5 is refused rather than rounded. Fractions in binary are well defined — the positions to the right of the point are worth a half, a quarter, an eighth — but a page that accepted them would have to decide how many of them to keep and how to round the last one, and every page in this group converts whole numbers. That keeps the boundary in the same place throughout, so a value is never accepted by one page and refused by another.
What is the largest decimal number I can convert here?
9007199254740991, whose binary form is fifty-three ones. The limit is not a choice made by this page: at that width a machine stops being able to tell neighbouring whole numbers apart, so a longer answer could not be trusted and is refused with a message rather than converted. The same ceiling appears on the reading page as a limit of fifty-three digits, and in hexadecimal as fourteen, because it is one limit written in three bases.
Why does the page print a place value sum as well as the binary number?
So the answer can be checked instead of taken on trust. The binary number is what you asked for, but there is no way to tell a correct 10001 from a wrong one by looking at it. Adding up the place values it holds — 16 and 1 here — gives the number you started with, which is the conversion run backwards. If the sum does not come back to your number, the binary string is wrong, and you know that without a second tool.
Is there a quicker way than dividing repeatedly?
For numbers you meet often, yes: learn the powers of two up to 1024 or so and subtract the largest that fits. 17 takes 16, leaving 1, so the answer is 10001 before you have written a single division. The ladder is better when the number is unfamiliar, because it needs no arithmetic you can get wrong — dividing by two repeatedly is mechanical. Both methods end at the same digits, and neither is more correct than the other.

References

Related calculators