How to rewrite a decimal number $x$ as $1.y\cdot2^{n}$?

35 Views Asked by At

If I have a number, let's say "$-77,51$", what is a good way to rewrite it as $1.y\cdot 2^{n}$?

2

There are 2 best solutions below

0
On BEST ANSWER

Given your number $n$, take $\log_2 (|n|)$ and round down to the next smaller integer. That gives you the power of $2$ you want to have the rest be between $1$ and $2$. In your example, $\log_2 (77.51)\approx 6.276$ so the exponent is $6$. Then $2^6=64$, so divide your number by $64$. $\frac {77.51}{64}\approx 1.2111$

0
On

$$x = \frac{x}{\lfloor{\log_2 x}\rfloor}\cdot {\lfloor{\log_2 x}\rfloor},\quad x>0$$