What is bitmasking in c++ and what are some cp problems I can practice bitmasking on or in scenarios is it most usefull | Sololearn: Learn to code for FREE!

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

c++

1/31/2021 10:20:37 PM

code0rdie

3 Answers

New Answer

+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)

+1

ChillPill ^.^