#include
void set_1(int *var,int i) //置1
{
*var |=(1<
}
void set_0(int *var,int i) //置0
{
*var &=~(1<
}
void invert(int *var) //反转
{
int i,temp=0x01;
for(i=0;i<8;i++)
{
if(temp & *var)
*var &=~(1<
else
*var |=(1<
temp<<=1;
}
}
int get_bit(int *var,int i) //获取某一位
{
return (*var & (0x01<}
int main()
{
int a=0x9b; //1001 1011
printf("%d\n",a);
set_1(&a,6);
printf("%d\n",a); //1101 1011
set_0(&a,6);
printf("%d\n",a); //1001 1011
invert(&a); //0110 0100
printf("%d\n",a);
printf("the 4st bit is %d\n",get_bit(&a,4));
}
阅读(1179) | 评论(0) | 转发(0) |