Transform expression from $2^{-n}$ to $x \times 10^{-m}$ I'm trying the understand the concept of how floating number are stored in the computer. While trying to understand it I ran into following kind of transformations:
$2^{-n} \approx x \times 10^{-m}$
For example:
$2^{-1074} \approx 5 \times 10^{-324}$
Can you please explain me how this transformation from the base 2 expression to the base 10 expression is being performed?
Thanks in advance
 A: You want to convert $a\times 2^b$ to $c\times 10^d$. Obviously, you noticed that $d=\lfloor \log (a\times 2^b)\rfloor$. So, now you need $c$ which is given by $c=a\times 10^{-d}\times 2^{b}$ what you get easily using logarithms. Hope it helps. ( Note: The floor function used to find the exponent "d" gives us the integer part of a number.)
A: $$2^{-n} = 10^{\log_{10}(2^{-n})} = 10^{-n \log_{10}(2)} \simeq 10^{-0.301n}.$$
Now, suppose that $n=42$. Then:
$$2^{-42} \simeq 10^{-12.643} = 10^{-0.643} \cdot 10^{-12} = x \cdot 10^{-m},$$
where
$x = 10^{-0.643}, m = 12$.
In general:
$$m = \text{int}(0.301n),$$
$$x = 10^{-(0.301n-m)},$$
where $\text{int}(\ldots)$ denotes the integer part of a number.
A: Log tables are what's used by a computer, as noted in the accepted answer.
However, you can approximate powers of two into powers of ten in your head, if you know that:
$2^{10} = 1024 \approx 1000 = 10^3$
This is a very rough approximation, but worth knowing.  It gets you in the right neighborhood.
Applying it to $2^{-1074}$, we get:
$2^{-1074} = 2^{-4} \times 2^{-1070} = 2^{6} \times 2^{-1080} = 2^{6} \times (2^{10})^{-108} \approx $
$2^{6} \times (10^3)^{-108} = 2^{6} \times 10^{-324} = 64 \times 10^{-324} \approx 6 \times 10^{-323} $
However, the rounding error involved adds up to a full order of magnitude in this case; the approximation given in your question is more accurate:
$5 \times 10^{-324}$
Still, this method is worth knowing for sanity-checking an answer within a few orders of magnitude in your head.
