Digital code of the high reference voltage of an A/D of a microcontroller
This is a mathematical problem. 

the digital code of n 1's corresponds to:

$$N = 1+\color{red}{2+2^2+2^3+\cdots +2^{n-1}}\tag1$$
multiplying equation \$(1)\$ with \$2\$:
$$2N = \color{red}{2+2^2+2^3+\cdots +2^{n-1}}+2^{n}\tag2$$

\$(2)-(1)\$ will give:
$$N = 2^n -1$$