Skip to content

Instantly share code, notes, and snippets.

@mrahul17
Created December 9, 2015 13:55
Show Gist options
  • Select an option

  • Save mrahul17/188079f3b3f021f699ef to your computer and use it in GitHub Desktop.

Select an option

Save mrahul17/188079f3b3f021f699ef 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