How to calculate how many times do I need to divide a number by 2 to get 1.xxx (close to 1)

7.4k Views Asked by At

I would like to know how do I calculate following number:

How many times do I need to divide a specific number to get a number that is one point something ( 1.xxx ).

Example for better understanding:

$10 / 2 = 5$ ($n=1$)

$5 / 2 = 2.5$ ($n=2$)

$2.5 / 2 = $1.25 ($n=3$)

In this case, the answer would be $n=3$. But how do I calculate it let's say for $120000$?

Many thanks to all in advance.

George

1

There are 1 best solutions below

0
On BEST ANSWER

Let $K$ be the number ($K>1$) that you want to divide. Say that you have to divide it $n$ times. Then $$1\le K/2^n<2$$ Therefore $$0=\log_2 1\le -n+\log_2 K<\log_2 2=1$$ $$n\le\log_2 K<n+1$$ $$n=\lfloor \log_2 K\rfloor$$