[模版] 位运算 转自USACO
2015-09-17 10:02
190 查看
a |= 0x20; /* turn on bit 0x20 */ a &= ~0x20; /* turn off bit 0x20 */ a ^= 0x20; /* toggle bit 0x20 */ if (a & 0x20) { /* then the 0x20 bit is on */ }
Binary Value Sample Meaning x 00101100 the original x value x & -x 00000100 extract lowest bit set x | -x 11111100 create mask for lowest-set-bit & bits to its left x ^ -x 11111000 create mask bits to left of lowest bit set x & (x-1) 00101000 strip off lowest bit set --> useful to process words in O(bits set) instead of O(nbits in a word) x | (x-1) 00101111 fill in all bits below lowest bit set x ^ (x-1) 00000111 create mask for lowest-set-bit & bits to its right ~x & (x-1) 00000011 create mask for bits to right of lowest bit set x | (x+1) 00101101 toggle lowest zero bit x / (x&-x) 00001011 shift number right so lowest set bit is at bit 0
相关文章推荐
- 23种设计模式
- 换个角度看微软:每年饮料费2300万
- 将一个字符串中的特定字符添加颜色
- 下載北風資料庫(NORTHWIND)
- AIX .tgz的安装包及登录日志查看
- Java基础之遍历Map
- 一、安装pip
- js判断undefined类型
- SAP客户标准信用额度修改和创建
- Fragment实现tabhost的效果
- HttpUtil
- 结构体struct简介(下)
- SignalR 2.0 系列:SignalR简介
- codeforces 204A A. Little Elephant and Interval(dp+组合数学)
- Java基础之遍历数组
- xpath- 一种xml解析器
- PPT转为PDF格式的方法汇总
- 大牛的面试总结
- 读懂IL代码就这么简单
- VC++中生成DLL和LIB文件