Bit manipulation
来源:互联网 发布:c语言英语单词 编辑:程序博客网 时间:2024/04/30 11:18
When should you use bitwise operators?
How many basic bitwise operations are there?
Source code that does bit manipulation usually makes use of the basic bitwise operations: AND, OR, XOR, NOT, and bit shifts.
As a reminder, here are the truth tables:
AND: 1 & 1 = 1, else are all 0
OR: 0 | 0 = 0, else are all 1
XOR: 1 ^ 0 = 0 ^ 1 = 1, else are 0
NOT: !0 = 1, !0 = 1
Left Shifts: 0001 << 1 = 0010, general bit_arg<<shift_arg equivalent to multiplication by 2^shift_arg
Right Shifts: 0010 >> 1 = 0001, general bit_arg>>shift_arg equivalent to division by 2^shift_arg
Some useful operations when coding.
Set union: A | B
Set intersection: A & B
Set subtration: A & ~B
Set negation: ALL_BITS_ONE ^ A
Assign 2^bit to be 1: A |= 1<<bit
Assign 2^bit to be 0: A &= ~(1<<bit)
Check if 2^bit is 1: (A & 1<<bit) != 0
References:
http://en.wikipedia.org/wiki/Bit_manipulation
http://www.cprogramming.com/tutorial/bitwise_operators.html
http://www.geeksforgeeks.org/fundamentals-of-algorithms/
- Bit Manipulation
- Bit manipulation
- Bit manipulation
- Bit manipulation
- Bit Manipulation
- Bit Manipulation
- Bit manipulation
- Bit Manipulation
- Bit Manipulation
- Chapter8 Bit Manipulation
- KNOW: Bit Manipulation
- leetcode Bit Manipulation
- Bit Manipulation Reverse Bits
- Bit Manipulation - Subsets
- Bit Manipulation - Reverse Bits
- Leetcode:bit manipulation
- CC150 Bit manipulation
- Leetcode bit manipulation 总结
- javascript实现原生的Java版本的HashMap及LinkedHashMap
- 面试题中常见的String类问题 .
- OpenCV图象孔洞内轮廓填充
- 奇葩的面试题
- Hbase与eclipse集成
- Bit manipulation
- 图表应用中缺失点的处理
- HDU 1847 Good Luck in CET-4 Everybody!
- win7 Visual Studio 2010 配置opencv 2.4.5 开发环境
- ContentProvider基础知识
- Java中的instanceof关键字
- c3p0
- HashSet与HashMap关系之源码分析
- Struts1+Hibernate+Spring整合(一)