+ 4

What real life applications do bitwise operators have?

I recently learned about the bitwise operators &, |, <<, >>, and ^. Unless if we're using && or || for if statements, I haven't seen these be used in actual coding. I was wondering if learning these have any actually useful applications in real world programming.

4th Mar 2018, 11:11 PM
Sheldon Duncan
Sheldon Duncan - avatar
3 ответов
+ 3
i've used them in competitive programming sometimes. ..for example if you have a number n=7 by doing n=n <<1; in c++ or c it's equal to multiply the number by 2 and by using the bitwise operation you are able to see if a number is power of 2 or to calculate what is the nearest power of 2 in not many lines
4th Mar 2018, 11:55 PM
Alessio Bocini
Alessio Bocini - avatar
+ 1
ok i made the same exaple i told you in words Ps: insert a number when you run it https://code.sololearn.com/cgMvOOz2N2Za/?ref=app
5th Mar 2018, 12:17 AM
Alessio Bocini
Alessio Bocini - avatar
0
You can use dev-c++
8th Mar 2018, 1:37 PM
Kaan TANRISEVER
Kaan TANRISEVER - avatar