算法测验|位算法|问题4

考虑下面的代码片段,检查一个数字是否是2的幂。

null

/* Incorrect function to check if x is power of 2*/
bool isPowerOfTwo (unsigned int x)
{
return (!(x&(x-1)));
}


上述功能有什么问题? (A) 它的作用与要求相反 (B) 它适用于所有x值。 (C) 它不适用于x=0 (D) 它不适用于x=1 答复: (C) 说明: 请看 https://www.geeksforgeeks.org/program-to-find-whether-a-no-is-power-of-two/ 这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享