bool result = false; result = CheckPowerOfTwo(8); Console.WriteLine(result.ToString()); static bool CheckPowerOfTwo(ulong number) { return (number != 0) && ((number & (number - 1)) == 0); }
7 如何检查一个数字是不是2的乘方
时间: 2024-11-10 15:45:42
bool result = false; result = CheckPowerOfTwo(8); Console.WriteLine(result.ToString()); static bool CheckPowerOfTwo(ulong number) { return (number != 0) && ((number & (number - 1)) == 0); }
7 如何检查一个数字是不是2的乘方