0

Write $0.2$ in binary such that the relative error is less than $0.005$

I know that the requirement is that $$\frac{|0.2-x|}{0.2}\leq 0.005$$

But how does it help to find the biggest sum of power of 2 that will be less than $0.005$ ?

gbox
  • 12,867
  • 1
    Why don't you try a few simple examples. First write out the binary expansion of $0.2$. Even try multiplying $0.2 \times 0.005$. – copper.hat Dec 31 '16 at 23:03
  • @copper.hat That what I did, but I am trying to see if there is a way to find it right away, meaning to which power at most I will need the binary expansion to be – gbox Dec 31 '16 at 23:06
  • @Moo: Why complicate things? – copper.hat Dec 31 '16 at 23:06
  • @Moo no, just binary – gbox Dec 31 '16 at 23:06
  • Do it one digit at a time. You can easily see that you need $x \in [0.199,0.201]$ so you can easily estimate how many digits you need. – copper.hat Dec 31 '16 at 23:08
  • @copper.hat when I have an integer I start with the largest power of 2 that is smaller than the number and then add powers, but in this case how can I estimate how many digits I will need? I know that $2^{-1}=0.5,2^{-2}=0.25,2^{-3}=0.125...$ – gbox Dec 31 '16 at 23:12
  • 2
    To get a resolution around the $0.002$ order, you will need around $|{\log(0.002) \over \log(2)}| \approx 9$ binary digits. Whether or not you need the digits depends on how close the number is to a 'nice' binary 'boundary'. – copper.hat Dec 31 '16 at 23:14
  • Why did you write what you wrote about "the biggest sum of power of $2$ that will be less than $0.005$"? If you were just looking for the largest power of $2$ less than "the number," why did you write "sum" and why do you want it less than $0.005$ rather than $0.2$? Did a person or book tell you to find this? If so, I hope they gave more a more detailed description or example of what kind of sum they meant. – David K Dec 31 '16 at 23:19
  • @DavidK I was asked to write $0.2$ in binary with a relative error of $0.005$. "The biggest sum of power of 2..." it is my way to write binary, in second thought it is better without my "input" – gbox Dec 31 '16 at 23:22

3 Answers3

3

You want to find a binary approximation to the decimal fraction $0.2$ to a precision of one-half of one percent, which is one part in $200$ of $0.2$ or one part in $1000$. The closest binary fraction to that requirement would be one part in $1024$. This is one part in the ninth bit to the right of the binary 'decimal' point or

\begin{eqnarray} 0.2&\approx&0\text{b}0.001100110\\ &=&\frac{1}{8}+\frac{1}{16}+\frac{1}{128}+\frac{1}{256}\\ &=&\frac{102}{512} \end{eqnarray}

\begin{equation} \frac{0.2-\frac{102}{512}}{0.2}\approx0.004<0.005 \end{equation}

2

In a comment, you mention that to write an integer in binary you would "start with the largest power of $2$ that is smaller than the number and then add powers."

The procedure for writing a non-integer value in binary begins just like that. "The number" in this case is $0.2$ (not $0.005$). When you find the largest power of $2$ that is less than $0.2$ you will have the first "$1$" digit of your number.

In general, unless the number you are trying to write is $m/2^n$ for some integers $m$ and $n,$ you can never write it exactly in binary. The actual binary representation of $0.2$ goes on and on for infinitely many digits (though after a while it's just the same pattern of digits over and over). Therefore this exercise has given you a condition under which you can stop writing digits.

It sounds like it is not time yet to try to learn any sophisticated method for deciding how many digits you need. It is straightforward enough to just start working out the digits one at a time. Every time you append another "$1$" digit to your answer, recalculate the decimal value of the digits you have written so far. When that number, substituted for $x,$ satisfies the equation $$\frac{|0.2-x|}{0.2}\leq 0.005,$$ then you have enough digits. Keep working out more digits until that happens.

Rather than recalculating $\frac{|0.2-x|}{0.2}$ for each new value $x,$ you may find it convenient to use the fact mentioned in one of the comments, namely, you are done when $0.199 < x < 0.201.$

David K
  • 98,388
1

recall that $5$ in binary is $101$, so when you multiply it by $3$ it becomes $15$, which is $1111$.

So the following number multiplied by $5$ is equal to $1$:

$0.\overline{0011}$, just take enough digits so that it is as precise as you need.

Asinomás
  • 105,651