C++ Bit masking with AND operation within if statement

  and-operator, bitmask, c++, iostream

I have an integer input and I should check every bit, whether it’s 0 or 1.
I have a code example that should print "result is 0", but it printed "result is 1".

#include <iostream>

using namespace std;
int main() {
    int mask = 0x80;
    int input = 0x03;
    if ((mask && input) == 0) {
        cout << "result is 0" << endl; 
    } else {
        cout << "result is 1" << endl;
    }
}

Source: Windows Questions C++

LEAVE A COMMENT