+ 1
What's the point of bitwise operations
Bitwise operations just seem like some assembly language stuff. Can someone explain their uses?
2 Answers
+ 3
Bitwise operations *can* by faster than their regular counterparts (like doing x>>1 instead of x//2). But I wouldn't recommend that. For example, if you do
x<<3 + x<<1 + x
instead of x*11, your code can get really hard to read. My suggestion would be to use bitwise operator only when you actually mean to use them (for example, when checking whether a number is a power of 2, or working with binary, like Maninder Singh suggested). Leave it to the interpreter to find the fastest way to do the arithmetic. Your colleagues will thank you later ;)
Zen of Python: https://www.python.org/dev/peps/pep-0020/
+ 3
Mostly bitwise operations use when you are working with binary.