Need a generalized way to solve $127=1+2+2^2+...$ How can I solve this equation generally? I can solve it by checking in my calculator. But I don't know any generalized way.

$$127=1+2+2^2+2^3+....+ 2^{x-1}$$
Let $S=1+2+2^2+2^3+....+ 2^{x-1}$, then $2S=2+2^2+2^3+....+ 2^{x}$. So $2S-S=S=2^{x}-1$. Can you take it from here?
Hint: $127=a\cdot \dfrac{r^{\text{number of terms}}-1}{r-1}$, where $a=$starting term, $r=$common ratio