TITLE: What is the minimum number of moves to change $a$ into $b$ by doubling and halving?
QUESTION [5 upvotes]: We are given integers $a$ and $b$, and wish to change $a$ to $b$ using these operations:
(1) Map $a \mapsto \lfloor \frac{a}{2} \rfloor$. (If $a$ is even, replace it with $\frac{a}{2}$. If $a$ is odd, replace it with $\frac{a − 1}{2}$.)
(2) Map $a \mapsto 2a$ (multiply $a$ by $2$).
What is the fewest number of operations required to get $a$ equal to $b$?
Also, $\boldsymbol{b}$ is always a power of 2.

Examples:

$a = 3$, $b = 8$: answer is $4$.
$a=4$, $b=1$: answer is $2$.

REPLY [2 votes]: It makes no sense to perform a double followed by a halve, because this leaves you where you started from. So you halve $a$ until it is a power of two; then you double or halve the result until it is equal to $b$.