Skip to content

Instantly share code, notes, and snippets.

@menangen
Created March 14, 2018 22:39
Show Gist options
  • Save menangen/7e630fbce1e3dbb5d1b640bd4171e14a to your computer and use it in GitHub Desktop.
Save menangen/7e630fbce1e3dbb5d1b640bd4171e14a to your computer and use it in GitHub Desktop.
Exponentiation by squaring
int ipow(int base, int exp)
{
int result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment