C++ Bitsets [C++ Reference]
Keywords: stl,bitset,start
Date: 2010-03-20T16:09:59-0700

[[C++ Bitsets]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

# 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.

Constructors | create new bitsets
Operators | compare and assign bitsets
any | true if any bits are set
count | returns the number of set bits
flip | reverses the bitset
none | true if no bits are set
reset | sets a single bit or all bits to zero
set | sets a single bit or all bits
size | number of bits that the bitset can hold
test | returns the value of a given bit
to_string | string representation of the bitset
to_ulong | returns 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()`

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •