如何对某一位置0或者置1?
2014-02-13 10:41
176 查看
int a|=(1<<x) //X就是某位需要置1的数字,如第四位置1为: a|=(1<<4)
int b&=~(1<<x) //把某位置0
x=x|0x0100 //把第三位置1
x=x&0x1011 //把第三位置0
#define BitGet(Number,pos) ((Number) >> (pos)&1)) //用宏得到某数的某位
#define BitGet(Number,pos) ((Number) |= 1<<(pos)) //把某位置1
#define BitGet(Number,pos) ((Number) &= ~(1<<(pos)) //把某位置0
#define BitGet(Number,pos) ((Number) ^= 1<<(pos)) //把Number的POS位取反
典型操作有:
WTCON |= (1 << 5) //WTCON的第五位清1
WTCON &= ~(1 << 5) //WTCON的第五位清0
int b&=~(1<<x) //把某位置0
x=x|0x0100 //把第三位置1
x=x&0x1011 //把第三位置0
#define BitGet(Number,pos) ((Number) >> (pos)&1)) //用宏得到某数的某位
#define BitGet(Number,pos) ((Number) |= 1<<(pos)) //把某位置1
#define BitGet(Number,pos) ((Number) &= ~(1<<(pos)) //把某位置0
#define BitGet(Number,pos) ((Number) ^= 1<<(pos)) //把Number的POS位取反
典型操作有:
WTCON |= (1 << 5) //WTCON的第五位清1
WTCON &= ~(1 << 5) //WTCON的第五位清0
相关文章推荐
- centos安装配置hadoop超详细过程(含故障排除)
- 我开始博客
- Linux中Sqlldr自动导入并更新数据
- cocos2d-x 3.0 beta 中 新增json搜索路径
- Java线程池
- mkdir 命令
- html5 文件系统(二)
- 为mysql设置访问权限
- SQL Server Service Broker(简称SSB)资料
- px与dip换算(2)
- 水处理过滤器在中水回用领域中技术应用
- Windows7使用Visual Studio 2010编译libpqxx 'copy' : return code '0x1'
- Android 内存监测工具 DDMS --> Heap
- Linux shell脚本的字符串截取
- linux修改TCP连接数(centos实测)
- kamailio配置rtpproxy
- java-01
- 博客园抽风
- 强大的JS数组
- ios之NSDictionary、NSMutableDictionary使用小结