# How do you convert a number from base $10$ to binary?

I don't understand how you get the binary representation of a number.

Say we have a number in base $$10$$, how do you change it into binary?

I used the Google math converter as well. . All I know is that $$a=a_n2^n+a_{n-1}2^{n-1}+\dotsb+a_0$$

• Note that the solutions below (appropriately modified) allow you to convert a decimal number into a number in any base. – Robert Shore May 29 at 0:30

You keep dividing your number by $$2$$, until you can't do it anymore. Say that, for instance, your number is $$19$$. Then:\begin{align}19&=9\times2+\color{red}1\\9&=4\times2+\color{red}1\\4&=2\times2+\color{red}0\\2&=1\times2+\color\red0\\1&=0\times2+\color{red}1\end{align}and therefore the binary expansion of $$19$$ is $$10\,011$$. This works for other bases too.

You also know that the $$a_i$$'s are either zero or one. One quick way to get the binary from base 10 is to divide the number by $$2$$, and then successively divide each quotient by $$2$$, and keep track of the remainders. Say you want to convert 100 base 10 into binary:

$$100 = 2\cdot 50 + 0$$ $$50 = 2\cdot 25 +0$$ $$25 = 2\cdot 12+1$$ $$12 = 2\cdot 6+0$$ $$6=2\cdot 3+0$$ $$3=2\cdot 1+1$$ $$1 = 2\cdot 0 +1$$

Now read off the remainders backwards: 1100100. That's 64+32+4 = 100.

Decompose the number into the sum of largest powers of two possible at each step.

For example, let's say we have the number 127. 64 is the largest power of 2 less than 127. 127 - 64 = 63, and then the largest power of 2 less than 64 is 32,... and so on

127 = 64 + 32 + 16 + 8 + 4 + 2 + 1

= $$2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1$$

The binary expansion of 127 is then: 1000000 + 100000 + 10000 + 1000 + 100 + 10 + 1 = 1111111 (base 2)

You can also do this thing. It is very unconventional but will let you convert base 10 to any base ( even fraction).

It works on basic principles of counting. You are adding balls to a box(let's say it unit). You add 1 then 2 and so on. When you reach 10, you empty the unit box and add just 1 ball to another one named tens. Extending this logic -each box can have maximum of 9 balls. -as soon as 10th ball it added, it is emptied and 1 ball is added to next index.

Now how to go about it? Let's say you want to convert base 10 to base n. Then units place=number%n (number/n be A) Next index= A%n (let A/n be B) Next index=B%n (let B/n be C) Add keep on doing so, you will know when to stop.

And if you recall, this is how you were taught numbers. This works with all the bases natural numbers, negative integers , fractions and irrational number although the last 3 won't have any physical significance.