What's the point of bitwise operations | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's the point of bitwise operations

Bitwise operations just seem like some assembly language stuff. Can someone explain their uses?

5th Aug 2018, 4:28 AM
Osinachi Chukwujama
Osinachi Chukwujama - avatar
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/
5th Aug 2018, 10:54 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Mostly bitwise operations use when you are working with binary.
5th Aug 2018, 5:02 AM
Maninder $ingh
Maninder $ingh - avatar