对指定位进行置0或置1操作

来源:互联网 发布:淘宝卖家收入在哪里看 编辑:程序博客网 时间:2024/05/21 09:00
#include<stdio.h>void bit_set(unsigned char *p, unsigned char position, int flag){if(flag==1){//11110000//00010000*p|=(1<<(position-1));}if(flag==0){//11110000//11101111*p&=~(1<<(position-1));}}int main(){unsigned char ch=13;printf("%d\n",ch);bit_set(&ch,2,1);printf("%d\n",ch);return 0;}

0 0
原创粉丝点击