# 如何判断一个数是不是2的n次幂

public static bool Check1(int num)

{
int i = 1;
while (true)
{
if (i > num)
return false;
if (i == num)
return true;
i = i * 2;
}
}

public static bool Check2(int num)
{
if (num == 1)
return true;
else
{
do
{
if (num % 2 == 0)
num = num / 2;
else
return false;
}
while (num != 1);
return true;
}
}

public static boolean getResult(int num)
{
if (num <= 1)
{
return false;
}
else
{
return ((num & (num - 1)) == 0) ? true : false;
}
}
public static void main(String[] args) {
System.out.println(getResult(32));
}

public static bool floor_7(int num)
{
if (num < 1)
{
return false;
}
else
{
return ((num & (num - 1)) == 0) ? true : false;
}
}

if ( n < 0 )
throw new InvalidOperationException();
if ( n < 2 )
return false;
return n & ( n - 1 ) == 0

public bool floor_8(int n)
{
if (n < 0)
throw new InvalidOperationException();
if (n < 2)
return false;
return n & (n - 1) == 0;
}

bool foo(int x)
{
float ret = log(x)/log(2);
return abs((int) ret - ret) <= 0.00001;
}

public bool floor_22(int x)
{
float ret = log(x) / log(2);
return abs((int)ret - ret) <= 0.00001;

}

static void Main(string[] args)
{
int i = int.Parse(Console.ReadLine());
Console.WriteLine(IsCheck(i));
}
public static bool IsCheck(int num)
{
double result = Math.Log(num, 2);
if (result.ToString().IndexOf(".") >= 0)
{
return false;
}
else
{
return true;
}

}

public static bool floor_37(int num)
{
double result = Math.Log(num, 2);
if (result.ToString().IndexOf(".") >= 0)
{
return false;
}
else
{
return true;
}
}

推荐：http://www.nowamagic.net/librarys/veda/detail/1031