Skip to content

Instantly share code, notes, and snippets.

@patrickgalbraith
Created September 21, 2018 14:02
Show Gist options
  • Save patrickgalbraith/92df3a41cf657989e320149498d7ce63 to your computer and use it in GitHub Desktop.
Save patrickgalbraith/92df3a41cf657989e320149498d7ce63 to your computer and use it in GitHub Desktop.
UInt32 Power Function
uint UIntPow(uint x, uint pow)
{
if (x == 0 || x == 1)
return x;
if (pow >= 32)
throw new OverflowException("Power exceeds allowed size for UInt32");
uint ret = 1;
while (pow != 0)
{
if ((pow & 1) == 1)
ret *= x;
x *= x;
pow >>= 1;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment