CShap 一个数是否为2的幂 源代码
时间: 2024-06-02 19:13:32 浏览: 84
SOAP教程C++CSHAP
bool IsPowerOfTwo(int number)
{
if (number <= 0)
{
return false;
}
return (number & (number - 1)) == 0;
}
//示例
int main()
{
int number = 16;
if (IsPowerOfTwo(number))
{
Console.WriteLine(number + " is a power of two.");
}
else
{
Console.WriteLine(number + " is not a power of two.");
}
return 0;
}
阅读全文