Translations of this page?:

C++ Bitsets

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

The size of a C++ bitset is fixed at compile-time, and the size is the template parameter to the bitset. If you wanted to use a bitset whose size you can fix at runtime, you can use dynamic_bitset from the Boost library.

Constructorscreate new bitsets
Operatorscompare and assign bitsets
anytrue if any bits are set
countreturns the number of set bits
flipreverses the bitset
nonetrue if no bits are set
resetsets a single bit or all bits to zero
setsets a single bit or all bits
sizenumber of bits that the bitset can hold
testreturns the value of a given bit
to_stringstring representation of the bitset
to_ulongreturns an integer representation of the bitset

Notes:

Bit set is missing two boolean queries to compliment any and none: all() and some().

  • all: (~bitset).none()
  • some: (~bitset).any()
 
• • • IndexRecent changesRSScc