#include <stdio.h>
int main()
{
short int a,b;
a=1;
b=1;
if ( (a | 65534)&1 == (b | 65534)&1 )
{
printf("The rightmost bit is the same");
}
else
{
printf("The rightmost bit is different");
}
return 0;
}
}
输出: 最右边的位不同
预期: 最右边的位是一样的
这里的“==”在“&”之前运行,这是不可取的。我可以使用另一个变量来解决这个问题,但不使用另一个变量是这个分配的重点......
答案 0 :(得分:1)
添加更多括号:
if ( ((a & 65534)&1) == ((b & 65534)&1) )