2009年3月26日 星期四

C語言的範例 –練習&和|的使用

C語言的範例 –練習&的使用
題目:學習使用按位與 & 。
1.程式分析:0&0=0; 0&1=0; 1&0=0; 1&1=1
2.程式源代碼:
#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語言的範例 –練習|的使用
題目:學習使用按位或 | 。
1.程式分析:0|0=0; 0|1=1; 1|0=1; 1|1=1            
2.程式源代碼:
#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);
}