# Solving equation with floor

Is it possible to solve for $i$ in the following equation?

EDIT- WolframAplha says it is possible but how do I do it?

$$\left \lfloor{\displaystyle \frac n{2^i}}\right \rfloor =1$$

I am not sure on how to separate the floor to solve for $i$

• If $\floor{x}=1$ then $1≤x<2$. Then just solve the inequality. May 30, 2018 at 6:40

$\lfloor x \rfloor = 1$ if and only if $1 \le x < 2$. Thus you want $2^i \le n < 2^{i+1}$. Take base-$2$ logarithms of both sides, and you find $i = \lfloor \log_2(n) \rfloor$.
We can introduce a slack variable $\epsilon$: $$1 = \lfloor n / 2^i \rfloor = n/2^i - \epsilon \quad (\epsilon \in [0,1))$$ Then $$1 + \epsilon = n / 2^i \iff \\ 2^i = n /(1+ \epsilon) \iff \\ i = \log_2(n/(1+\epsilon))$$ This means $$\log_2(n/2) < i \le \log_2(n)$$ You might want $i \in \mathbb{Z}$ as well (going by the name). Because we have $$\log_2(n) - \log_2(n/2) = \log_2(n/(n/2)) = \log_2(2) = 1$$ we can now go reverse and have $$i = \log_2(n) - \epsilon' = \lfloor \log_2(n) \rfloor \quad (\epsilon' \in [0,1))$$