# Converting Numbers from Decimal to Binary

> Learn how to convert a decimal number to binary by repeatedly dividing the integer by 2, noting each remainder, then reversing the list to read the result.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-01-14 | Topics: [Computer](https://flaviocopes.com/tags/computers/) | Canonical: https://flaviocopes.com/converting-decimal-to-binary/

I recently introduced the [Decimal Number System](https://flaviocopes.com/decimal-number-system/), the one we are used as humans, and the [Binary Number System](https://flaviocopes.com/binary-number-system/), the one machines are used to.

In this tutorial I want to explain how to convert from decimal numbers to binary numbers.

If you want to check a result without doing the division by hand, I built a free [number base converter](https://flaviocopes.com/tools/number-base/) that converts between decimal, binary, and hex.

We have a separate process for integers, and for fractions.

## Converting an integer from decimal to binary

A decimal integer can be converted to binary by dividing it by 2.

Take the quotient, and keep dividing it by 2, until you reach zero.

Each time you perform this division, take note of the **remainder**. Now reverse the remainders list, and you get the number in binary form.

Let's make an example, I want to convert 29 into binary:

<p class="inline">
\[29\div2 = 14\] remainder <code>1</code>
</p>

<br>

<p class="inline">
\[14\div2 = 7\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[7\div2 = 3\] remainder <code>1</code>
</p>

<br>

<p class="inline">
\[3\div2 = 1\] remainder <code>1</code>
</p>

<br>

<p class="inline">
\[1\div2 = 0\] remainder <code>1</code>
</p>

<br><br>

The binary number representing the 29 decimal is `11101`.

Another example, let's convert 145 decimal into binary.

<p class="inline">
\[145\div2 = 72\] remainder <code>1</code>
</p>

<br>

<p class="inline">
\[72\div2 = 36\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[36\div2 = 18\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[18\div2 = 9\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[9\div2 = 4\] remainder <code>1</code>
</p>

<br>

<p class="inline">
\[4\div2 = 2\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[2\div2 = 1\] remainder <code>0</code>
</p>

<br>

<p class="inline">
\[1\div2 = 0\] remainder <code>1</code>
</p>

<br><br>

The binary number representing the 145 decimal is `10010001`.

## Converting a fraction from decimal to binary

The decimal part of the fraction is converted separately like we did above. To convert the fractional part you need to multiply it by 2.

If the integer part of the fraction is still less than `1`, assign it a `0`. If it's > `1`, then assign it a `1`, then keep multiplying by 2 and following this scheme.

You stop when the fractional part is equal to 0.

This might never happen, and you have a periodic fraction. In this case after some point you stop. The more digits the number has, in this case, the more precision it has.

Let's make an example. I want to convert `0.375` to binary.

<p class="inline">
\[0.375\times2 = 0.75 \implies 0\]
</p>

<br>

<p class="inline">
\[0.75\times2 = 1.5 \implies 1\]
</p>

<br>

<p class="inline">
\[0.5\times2 = 1 \implies 1\]
</p>

<br>
<br>

You take the number `0` or `1` that depends on being > `1`, and you read it from top to bottom (instead of bottom to top like we do for the integer part). The final binary that translates `.375` is `011`.

At this point you take the integer part (`0`) and the fractional part (`011`) separately, and you compose them.

The number `0.375` converted to binary is `0.011`
