0
What is bitmasking in c++ and what are some cp problems I can practice bitmasking on or in scenarios is it most usefull
Bitmask, Competitive Programming
2 Réponses
+ 5
bitmasking is using bitwise operators and, or, xor... wich help you to get/set/toggle bits of an integer value.
to practice those, you could try to implement integer operation using only bitwise op.
bitmasking is also usefull in scenario where you store multi true/false values (1 or 0) inside only one integer... for example you could retrieve the value of the nth bit (from right to left) by left shifting 1 by n-1 then doing an 'and' op between this value and the flags variable:
int flags = 9;
int f = 1 << 3; // get the 4th bit
cout << f & flags; // print the 4th bit value (wich is 0 or 2 power 3, false or true)