Everytime I do a contest that has a problem involving bitmasking, I never know it was a bitmasking question. They would end up using bitmasking in a way such as brute forcing a solution. For the problems that do involve bitmasking, it seems like the editorial just pulled random masks out of thin air, like x >> i & 2 etc, etc. I understand the basics of bitmasking such as what >> and << means and what & 1 means. But I don't understand how to actually come up with these mask solutions because they seem like voodoo magic at the moment where the solution just comes up. How do you actually learn how to solve bitmasking questions? Do you just draw out the binary representation of every number and hopefully find something??