mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-02 06:46:18 -04:00
👾
This commit is contained in:
parent
1d44d182e2
commit
a85ed914d3
320 changed files with 0 additions and 0 deletions
33
MY_BOOK/ebook_src/bitwise_operations/bitwise.txt
Executable file
33
MY_BOOK/ebook_src/bitwise_operations/bitwise.txt
Executable file
|
@ -0,0 +1,33 @@
|
|||
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!
|
Loading…
Add table
Add a link
Reference in a new issue