一、C语言按位与&实例
程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1
程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a&3;
printf("\40: The a & b(decimal) is %d \n",b);
b&=7;
printf("\40: The a & b(decimal) is %d \n",b);
}
二、C语言按位或| 实例
程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a|3;
printf("\40: The a & b(decimal) is %d \n",b);
b|=7;
printf("\40: The a & b(decimal) is %d \n",b);
}
三、C语言按位异或^ 的实例
程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0
程序源代码:
#include "stdio.h"
main()
{
int a,b;
a=077;
b=a^3;
printf("\40: The a & b(decimal) is %d \n",b);
b^=7;
printf("\40: The a & b(decimal) is %d \n",b);
}