C++ Bitsets

C++ Bitsets give the programmer a set of bits as a data structure. Bitsets can be manipulated by using various binary operators such as logical AND, OR, XOR and so on.

Bitset Constructors
  • any - returns true(1) if any bits are set else return false (0)
  • count - returns the number of set bits ie. how many bits are 1 in the binary representation of the given number.
  • flip - reverses the bitset
  • none - returns true (1)  if no bits are set else false (1) if any of the bits are set.
  • reset - sets bits to zero
  • set - sets bits
  • size - outputs the number of bits that the bitset can hold
  • test - return the value of a given bit
  • to_string - convert the bitset data to the string representation of the bitset.
    • like we have bitset 11001110 then to string it will be "11001110".
  • to_ulong - returns an unsigned long integer representation of the bitset
Below is the implementation of some of this function and rest can be used in the same way.

If you find any error or have any query then feel free to comment.

Thank You
Happy Coding!