Skip to content

Converting Numbers from Decimal to Binary

How to quickly convert a number expressed in the Decimal Number System to the Binary Number System

I recently introduced the Decimal Number System, the one we are used as humans, and the 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.

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:

\[29\div2 = 14\] remainder 1


\[14\div2 = 7\] remainder 0


\[7\div2 = 3\] remainder 1


\[3\div2 = 1\] remainder 1


\[1\div2 = 0\] remainder 1



The binary number representing the 29 decimal is 11101.

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

\[145\div2 = 72\] remainder 1


\[72\div2 = 36\] remainder 0


\[36\div2 = 18\] remainder 0


\[18\div2 = 9\] remainder 0


\[9\div2 = 4\] remainder 1


\[4\div2 = 2\] remainder 0


\[2\div2 = 1\] remainder 0


\[1\div2 = 0\] remainder 1



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.

\[0.375\times2 = 0.75 \implies 0\]


\[0.75\times2 = 1.5 \implies 1\]


\[0.5\times2 = 1 \implies 1\]



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


download all my books for free

  • javascript handbook
  • typescript handbook
  • css handbook
  • node.js handbook
  • astro handbook
  • html handbook
  • next.js pages router handbook
  • alpine.js handbook
  • htmx handbook
  • react handbook
  • sql handbook
  • git cheat sheet
  • laravel handbook
  • express handbook
  • swift handbook
  • go handbook
  • php handbook
  • python handbook
  • cli handbook
  • c handbook

subscribe to my newsletter to get them

Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing flavio@flaviocopes.com. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.

Related posts about computers: