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

What's the use of Bitwise Operators?

24th Aug 2018, 4:31 PM
Emilio Rivers
Emilio Rivers - avatar
2 Answers
0
The | operator is often used to combine flags, and so to save parameters and make your memory footprint smaller. Example: const int SHOW = 0b0001; const int FIXED_SIZE = 0b0010; const int HIGH_PRIORITY = 0b0100; // Window(string name, int flags) // 0001 // 0010 | // 0100 | // = // 0111 int flags = SHOW | FIXED_SIZE | HIGH_PRIORITY; Window window = Window("A new Window", flags);
24th Aug 2018, 6:02 PM
StoneSmasher
StoneSmasher - avatar
0
If you go a abstraction degree deeper, for example assembler language, you will notice that the language hasn't such keywords like "if, else, for, while". You must build your programs mostly with bitwise operations. So you can do actually all with bitwise operations, but if you programming with higher level languages, you don't need this. So the use is... actually to make some low level Mathematical Algebra.
24th Aug 2018, 7:14 PM
BraveHornet
BraveHornet - avatar