13. March 2010 10:09
/
Vitaly Zayko
/
/
Comments (0)
Continue playing with Integers. Here is how to determine if a number is power of 2 or not:
/// <summary>
/// Checks if an integer is power of 2
/// </summary>
/// <param name="i">An int number to check</param>
/// <returns>true if i is power of 2, false if otherwise</returns>
public static bool IsPower2(int i)
{
return (i != 0) && ((i & -i) == i);
}
077b7c46-4b87-4991-85bd-d5a63312b515|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04