#include <stdio.h>
int main(){
printf("%d,%d\n", 2 & (1<<1) , 2 & (1<<1)>0 );
return 0;
}
the output of this program is 2,0
.
2 & (1<<1)
is equal to 2 which is more than 0.
so why does 2 & (1<<1) > 0
evaluate to zero??
#include <stdio.h>
int main(){
printf("%d,%d\n", 2 & (1<<1) , 2 & (1<<1)>0 );
return 0;
}
the output of this program is 2,0
.
2 & (1<<1)
is equal to 2 which is more than 0.
so why does 2 & (1<<1) > 0
evaluate to zero??
Copyright © 2021 Jogjafile Inc.
This expression
is equivalent to
due to the precedence of the operators. That is the relational operator > has a higher precedence than the bitwise AND operator. As
1 << 1
is greater than0
then the sub-expression( ( 1 << 1 ) > 0 )
yields the value1
.So
2 & 1
yields0
because in binary1
can be represented (for simplicity) like01
and2
- like10
andIt seems what you mean is the following expression