For example:
say $n = 2$.
The numbers from $1$ to $2^2$ are $1, 2, 3, 4$.
i.e. $1, 10, 11, 100$ in binary.
So the result is $1$, because only one number i.e. $3$ is there such that it has 11 in it.
For $n = 3$, $3, 6, 7$ have '11', so the result is $3$.