把一个数的第三位进行清零、置位、取反

来源:互联网 发布:大数据专业课程 编辑:程序博客网 时间:2024/06/08 07:07
#include <stdio.h>#define Bit3 (0X01<<3)/*对一个数的第三位进行清零、置位、取反*/int main(){int a=15 ;      // 0000 1111printf("原大小:%d\n", a);a &= ~Bit3;     //清零, 0000 0111printf("清零后:%d\n", a);a |= Bit3;     //置位, 0000 1111printf("置位后:%d\n", a);a ^= Bit3;     //取反, 0000 0111printf("取反后:%d\n", a);return 0;}   

0 0
原创粉丝点击