C++ uint64_t按位并检查偶数

0 c bit-manipulation bitwise-operators uint64 bitwise-and

我有以下代码,只是检查uint64_t是否是偶数,我打算使用按位AND操作来检查,但它似乎没有工作.

这是我认为首先工作的代码:

int n;
scanf("%d",&n);
for(int i = 0; i < n; i++){
    uint64_t s,d;
    scanf("%llu %llu",&s,&d);
    //try for x
    uint64_t x;
    bool stop = false;
    x = s + d;
    printf("%llu",x&1ULL); \\ This prints 0 when the number is even but
    if(x&1ULL==0ULL){ \\ This check always returns false
        printf("%llu",x);
        x/= 2;
Run Code Online (Sandbox Code Playgroud)

如果数字是奇数或偶数,则此代码始终打印输出0或1,但if语句始终返回false.我究竟做错了什么?谢谢

Ala*_*kes 5

x&1ULL==0ULL相当于x&(1ULL==0ULL).你需要(x&1ULL)==0ULL.