Converting from base $10$ to base $2$

1.6k Views Asked by At

I am attempting to solve the following two questions. The first question I believe I have done correctly and I am looking to confirm this answer. The second question I am not sure about.

$1)$ Convert $5.1$ in base $10$ to base $2$

My solution.

Looking at the whole number to the left of the decimal $5$

$$(5)_{10} = 2^2+1 = 2^2 + 2^0 = 1\cdot2^2 + 0\cdot 2^1 + 1 \cdot2^0 = (101)_2$$

Looking at the decimal part:

How do I calculate this?

My other question is can this answered be stored exactly on a computer?

3

There are 3 best solutions below

10
On BEST ANSWER

Note that $0.1=\frac1{10}=\frac12\times\frac15$. Now,\begin{align}\frac15&=\frac3{15}\\&=\frac3{2^4-1}\\&=\frac{3\times2^{-4}}{1-2^{-4}}\\&=3\times2^{-4}\times(1+2^{-4}+2^{-8}+2^{-12}+\cdots)\\&=3\times(2^{-4}+2^{-8}+2^{-12}+2^{-16}+\cdots). \end{align}So, since $3_{10}=11_2$, the binary representation of $\frac15$ is$$0.001100110011\ldots$$and therefore the binary representation of $\frac1{10}$ is$$0.0001100110011\ldots$$Finally, the binary representaion of $5.1$ is$$101.0001100110011\ldots$$This cannot be stored exactly in a binary computer, since it has infinitely many digits.

3
On

Numerically you can convert $0.1$ by repeatedly multiplying the fractional part by $2$

0.1 * 2 = 0.2    ->  1. binary digit = 0
0.2 * 2 = 0.4    ->  2. binary digit = 0
0.4 * 2 = 0.8    ->  3. binary digit = 0
0.8 * 2 = 1.6    ->  4. binary digit = 1
0.6 * 2 = 1.2    ->  5. binary digit = 1
0.2 * 2 = 0.4    ->  6. binary digit = 0
....

Now it is periodic and you get $$0.1_{10} = 0.0001100110011001100110011001100110011001100110011\cdots_{2}\\ = 0.0\overline{0011}_{2}$$

Since it is periodic it cannot be exactly stored as binary floating point.

0
On

I’d do it this way:

$0.1=\frac1{10}=\frac12\cdot\frac15$

Now $1/5$ in base $2$ is the result of the division $1_2 \div 101_2$, so you can set up a long division and divide $101_2$ into $1.000\ldots_2$. It will be periodic, with period not exceeding $4$.

Finally, multiplying by $\frac12$ is simply a digit shift (or should I say, a bit shift).