C++ STL: bitset

C++ STL: Bitset:-

A bitset stores bits. Can be imagined as an array of bool elements, but space-optimized. Each element occupies only one bit.
You can declare a bitset as follows 
bitset<length> bits;
Each bit can be accessed individually.  bits[0], gives the first bit of the sequence(isn't it analogous to arrays).

Imp: Bitset has the features of being able to be constructed from and converted to both integer values and binary strings.
to_ulong and to_string are used to do so.

The size of bitset is fixed at compile time(you need to pass it at the time of writing the code).

Member functions:

Bit access

  • count: count bits in the set.
  • size: returns the size
  • test(location): return 1 if the bit at the "location" is set else return zero.
  • any: test if any bit is set.
  • none: test if no bit is set.
  • all: test if all bits are set.

Bit operations

  • set: set bits
  • reset: reset bits
  • flip: flip bits
  • to_string: convert to string
  • to_ulong: convert to an unsigned long integer
  • to_ullong: convert to unsigned long long
Here is the link to the official documentation for bitsets: http://www.cplusplus.com/reference/bitset/bitset/

No comments:

Post a Comment

Installing albert on ubuntu 19.04

Installing Albert on Ubuntu 19.04... Albert is not still released for ubuntu 19.04. But still, you can install it using the following ...