+ 5
>> and << in python ?
what are these and how to use them.
3 Answers
+ 8
They are bitwise operators, this link may help.
https://www.sololearn.com/learn/4070/?ref=app
e. g.
2 << 3 gives 16.
2 = 10 (in binary)
then shift to the left by three digit.
10 turns into 10000
16 = 10000 (in binary)
+ 2
The idea is that it is a very fast way to multiply or divide by 2^k
- 1
>> is moving all the bits one place to the right and << is the same, just to the left