标签:c语言
#include <stdio.h> unsigned int set_bit(unsigned int num, int pos, int flag) { int n = 1; n = n << pos; //将n的第pos位置1,其他全为0 if (flag == 0) { num = num&(~n); } else if (flag == 1) { num = num | n; } return num; }
调用如下:
int a = 0x10; a = set_bit(a,1,1);//将a的第1位,置1,结果为10010即0x12
标签:c语言
原文地址:http://9233403.blog.51cto.com/9223403/1971827