Bit Operations
Bit Representation

10转2进制
2转10进制
ASCII
Unicode
Bit Operation
& bitwise AND(&&)
| bitwise OR ||
~ NOT
^ XOR

<< 左移 右侧补充零
>> 右移 算术右移 左侧补充符号位
>>> 右移 逻辑右移 左侧补充0, 叫做unsigned right shift
Practical Use Cases
Compression
Building Blocks
Bit tester: Given a number, whether its kth bit is 1
Bit setter: Set kth bit to 1, and the rest stays the same
Bit setter: Set kth bit to 0, and the rest stays the same
Problems
Determine whether a number x is a power of 2 (2^n, n>=0)
Determine the # of bits are different between 2 positive integers
如何数1: Hamming Weight
What happens if we assign a negative number to an unsigned integer
Determine whether a string contains unique characters
hashset size=26
boolean array, size =26
bitmap
How to reverse all bits of a number
用2 pointers,reverse string的方法
10进制Number to 16进制
实现Integer.parseint这个method
Convert 'd'-->'D'
Char to Hex digit
Last updated