#include<stdio.h>
void bit_set(unsigned char *p_date, unsigned char position, int flag)
{
if (flag == 1)
{
*p_date |= (1 << (position - 1));//0000 0010或0000 0001
} // 0000 0011
else if (flag = 0)
{
*p_date &= ~(1 << (position - 1));//0000 0010&1111 1110
} // 0000 0010
}
int main()
{
unsigned char val = 2;
bit_set(&val, 1, 0);
printf("%d\n", val);
getchar();
return 0;
}原文地址:http://blog.csdn.net/yangrujing/article/details/46419637