Skip to content

Instantly share code, notes, and snippets.

@cerebrate
Created February 4, 2013 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cerebrate/4708009 to your computer and use it in GitHub Desktop.
Save cerebrate/4708009 to your computer and use it in GitHub Desktop.
Raising to a power using an extension method.
public static int Exp(this int x, int y)
{
int result = 1;
while (y > 0)
{
if ((y & 1) != 0)
{
result *= x;
}
y >>= 1;
x *= x;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment