This is the same as Horner's method for evaluating polynomials. It works because
$$a_n2^n+a_{n-1}2^{n-1}+...+a_12+a_0=2(...(2(2(2a_n+a_{n-1})+a_{n-1})...+a_1)+a_0$$
If the formula in general looks obscure, you can try it for small values of $n$. For example, $n=3$: $$2^3a_3+2^2a_2+2a_1+a_0=2(2(2a_3+a_2)+a_1)+a_0$$