include
using namespace std;
int main() {
int x=5;
int y=x & 2;
cout << y<<endl;
x=3;
y=x & 2;
cout<<y;
return 0;
}
/* OUTPUT IS 0 AND 3
PLEASE EXPLAIN THIS STRANGE OUTPUT
*/
using namespace std;
int main() {
int x=5;
int y=x & 2;
cout << y<<endl;
x=3;
y=x & 2;
cout<<y;
return 0;
}
/* OUTPUT IS 0 AND 3
PLEASE EXPLAIN THIS STRANGE OUTPUT
*/
I get
0
2
which seems correct to me.
But what is meaning of y=x & 2;
Explain please…
It assigns the bitwise AND of x and 2 to y.
x=5, in binary, is:
101
2 in binary is
010
so 5 \& 2 is
000
Thankyou I got it …