Smallest number of steps to reach from X to Y You are provided a number X and another number Y.
You can apply only the following operations : -
a) If the number is even, either double the number or increase it by 1.
b) If the number is odd, either double the number or decrease it by 1.  
What should be the minimum number of steps to convert X to Y?    
For example - If $X = 4$, and $Y = 11$ , the answer is $3$.
$4\to 5\to 10\to 11$.  
There can be cases where answer is not reachable at all like $X=4, Y=6$.

In binary, you can either toggle the least significant bit or append a 0 bit.
Consequently, there is (up to loops) only one way to get from an $n$-bit number $X$ to an $m$-bit number $Y$: 


*

*If $n>m$ or the first $n-1$ bits of $X$ differ from the first $n-1$ bits of $Y$, no solution is possible. Terminate

*ensure that the first $n$ bits of $X$ are the same as the first $n$ bits of $Y$ by toggling if necessary.

*If you have reached $Y$, terminate

*Double $X$ and go back to step 2.


The number of operations performed is apparently: $m-n$ to account for all doublings, plus the number of $1$'s in the lower $m-n$ bits of $Y$, plus possibly $1$ is the least significant of $X$ starts out wrong.
