How to become a bitWISE user

What is the main motivation behind using bitwise operators in a program? I have seen certain experienced programmers using extensive amount of bitwise operators (&,|,^,<<,>>) in their code to solve a difficult problem in a few lines.

Could someone please provide some tutorials that explain how to implement bitwise operators? Also, some links to problems that require usage of bitwise operators would be appreciated. Thanks in advance.

  1. They are really fast for operations like divide by a power of 2, multiply by a power of 2, check if a number n is a power of 2, etc.
  2. A bitmask used to represent a set and all its subsets is manipulated by these operators. It is used to solve many problems. Here is a tutorial on how to manipulate a bitmask using these operators : link.
    Here is a problem using bitmask + DP : link
1 Like

Thanks. Any more problems of such type?

well there are some problems in the first answer of this : also here is a relatively easy version of the first problem :

1 Like

Thanks man.