+ 1
What's the use of Bitwise Operators?
2 Réponses
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);
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.