Square and multiply algorithm I'm trying to understand the square and multiply algorithm:

If I understand it correctly, whenever the exponent is even, we divide it by 2 but square the base, and whenever it is odd, we take an x out and subtract 1 off the exponent.
So, when running the algorithm on $2^{10}$, I was expecting the following to happen:
10 is even, so we square: $(2^2) ^5$
5 is odd, so we subtract 1 and take an x out: $2*(2^2) ^4$
But this is obviously 512 and not 1024 anymore.

Error: in second step, As @Kenny mentioned, $x$ should be $2^2$ instead of $2$.  We are talking about $(x^2)^{y/2}$ and here, $x$ happens to be $2^2$
