Convert numbers from decimal to binary

How to quickly convert a number represented by a decimal number system to a binary number system

I recently introducedDecimal system, We are used as humanBinary number system, A machine is used to it.

In this tutorial, I want to explain how to convert from a decimal number to a binary number.

We have a separate process for handling integers and fractions.

Convert integer from decimal to binary

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

Take the quotient and divide it by 2 until it reaches zero.

Every time you perform this division, please noteMore than. Now reverse the remainder list and you will get the number in binary form.

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

\ [29 \ div2 = 14 \] remainder1


\ [14 \ div2 = 7 \] remainder0


\ [7 \ div2 = 3 \] remainder1


\ [3 \ div2 = 1 \] remainder1


\ [1 \ div2 = 0 \] remainder1



The binary number representing 29 decimal places is11101.

As another example, let us convert 145 decimals to binary.

\ [145 \ div2 = 72 \] remainder1


\ [72 \ div2 = 36 \] remainder0


\ [36 \ div2 = 18 \] remainder0


\ [18 \ div2 = 9 \] remainder0


\ [9 \ div2 = 4 \] remainder1


\ [4 \ div2 = 2 \] remainder0


\ [2 \ div2 = 1 \] remainder0


\ [1 \ div2 = 0 \] remainder1



The binary number representing 145 decimals is10010001.

Convert 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 than1, Assign it a0. If it is>1, And assign it a1, And then continue to multiply by 2 and follow this scheme.

You stop when the fractional part is equal to 0.

This may never happen, and you have periodic scores. In this case, you have to stop. In this case, the more numbers, the higher the accuracy.

Let us take an example. I want to switch0.375To binary.

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


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


\ [0.5 \ times2 = 1 \ means 1 \]



You take the number0or1Depends>1, And then read from top to bottom (rather than from bottom to top as we did for the integer part). Final translated binary file.375Yes011.

At this time, you take the integer part (0) And the decimal part (011), and then compose them.

digital0.375Convert to binary is0.011


More computer tutorials: