64bit - NOT of 64 bit number giving wrong results in c

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

there are two numbers a and b, both 64 bits.

Code:

a = a|b;

if(!(a&b)){ }

Now in the above scenario b s 34th bit is on and a have some bits on. So, according to the situation !(a&b) should result in 0 but the code is entering in the if loop which is wrong. The problem is that !(a&b) is giving 1 instead of 0. Any reasons?

Answers

http://sscce.org/ http://sscce.org/

#include <stdio.h>

int main(void) {
    unsigned long long a = 42, b = 1ULL << 33;

    a = a|b;
    if(!(a&b))
        printf("!(a&b)
");
    else
        printf("(a&b)
");

    return 0;
}

http://ideone.com/0Hif2t http://ideone.com/0Hif2t

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/17176601/not-of-64-bit-number-giving-wrong-results-in-c

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils