2018-06-14 15:50:29 -07:00

34 lines
503 B
Plaintext
Executable File

BIT-WISE
----------------------
1. To find a number:
11000101 is 2^0+2^2+2^6+2^7 = 197
2. Left shifting:
0010 1011 << 4 ---> 1011 000
3. Right shifting:
0010 1011 >> 4 ---> 0000 0010
or it can be filled with the copy of the first bit, instead of 0:
1011 0010 >> 4 ---> 1111 1011
4. XOR can cancels out:
15 ^ 12 ^ 15 = 12
5. 2^x:
left-shift 1 by x:
0000 0001 << x
so if x = 2, 2^2 = 4 -> 100
0000 0001 << 2 ---> 0000 0100
6. Is power of 2?
just do x&(x-1).
if 0 --> yes!