#include<stdio.h>#include<stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */#definebitRead(value,bitx)(((value)>>(bitx))&0x01)#definebitSet(value,bitx)((value)|=(0x01<< bitx))#definebitClear(value,bitx)((value)&=~(0x01<<(bitx)))#definebitToggle(value,bitx)((value)^=(1<<bitx))#definebitWrite(value,bitx,bitxvalue)(bitxvalue?bitSet(value,bitx):bitClear(value,bitx))voidprint_bin(int number){int bit =sizeof(int)*8;int i;for(i = bit -1;i >=0;i--){int bin =(number &(1<< i))>> i;printf("%d", bin);}printf("\n");}intmain(int argc,char*argv[]){unsignedchar valuetemp;unsignedchar a,b,c;
valuetemp =0xFF;print_bin(valuetemp);
valuetemp =0x12;print_bin(valuetemp);
a=bitRead(valuetemp,1);printf("a0=%d\r\n",a);
a=bitRead(valuetemp,0);printf("a1=%d\r\n",a);bitToggle(valuetemp,1);
a=bitRead(valuetemp,1);printf("a2=%d\r\n",a);return0;}