错误:
Test isPower2(0[0x0]) failed.
Gives 1[0x1]. Should be 0[0x0]
代码:
int isPower2(int x) {
int nonNega = (x>>31);
int result = !((x & (x-1)) ^ nonNega);
return result;
}
最佳答案
您的 isPower2(0)
返回 true (1),但 0 不是 2 的幂。因此预期结果将为 false (0)。
关于c - 当我运行代码时,它在终端上显示一些错误。谁能告诉我错误代表什么?我该如何调试它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50813811/