(某数&0x04)等价于((某数&0x4)==0x4)

类似汇编的test

#include<stdio.h>
#include<string.h>
void fun(int s)
{
printf("- is hex:%x dec:%d\n",s,s);
if(s&0x4)printf("-&04\n");
if(s&0x2)printf("-&2\n");
if((s&0x4)==0x4)printf("(-&04)==0x4\n");
if((s&0x4)==1)printf("(-&04)==1\n");
if((s&0x01)==1)printf("(-&0x01)==1\n");
}
int main()
{

int s=0x4;
fun(s);
printf("==============\n");
fun(0x46);
printf("==============\n");
fun(0xf2);
printf("==============\n");
fun(0xf7);
return 0;
}


- is hex:4 dec:4


-&04


(-&04)==0x4


==============


- is hex:46 dec:70


-&04


-&2


(-&04)==0x4


==============


- is hex:f2 dec:242


-&2


==============


- is hex:f7 dec:247


-&04


-&2


(-&04)==0x4


(-&0x01)==1