##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::bitset

From cppreference.com
< cpp‎ | utility

Defined in header `<bitset>` |  |
template< std::size_t N > class bitset; |  |

The class template `bitset` represents a fixed-size sequence of `N` bits. Bitsets can be manipulated by standard logic operators and converted to and from strings and integers.

`bitset` meets the requirements of `CopyConstructible` and `CopyAssignable`.

### [edit] Template parameters

N | - | the number of bits to allocate storage for

### [edit] Member types

reference | proxy class representing a reference to a bit (class)

### [edit] Member functions

(constructor) | constructs the bitset (public member function) [edit]
operator==operator!= | compares the contents (public member function) [edit]
##### Element access
operator[] | accesses specific bit (public member function) [edit]
test | accesses specific bit (public member function) [edit]
all any none (C++11) | checks if all, any or none bits are set to true (public member function) [edit]
count | returns the number of bits set to true (public member function) [edit]
##### Capacity
size | returns the size number of bits that the bitset can hold (public member function) [edit]
##### Modifiers
operator&=operator|=operator^=operator~ | performs binary AND, OR, XOR and NOT (public member function) [edit]
operator<<=operator>>=operator<<operator>> | performs binary shift left and shift right (public member function) [edit]
set | sets bits to true or given value (public member function) [edit]
reset | sets bits to false (public member function) [edit]
flip | toggles the values of bits (public member function) [edit]
##### Conversions
to_string | returns a string representation of the data (public member function) [edit]
to_ulong | returns an unsigned long integer representation of the data (public member function) [edit]
to_ullong (C++11) | returns an unsigned long long integer representation of the data (public member function) [edit]

### [edit] Non-member functions

operator&operator|operator^ | performs binary logic operations on bitsets (function template) [edit]
operator<<operator>> | performs stream input and output of bitsets (function template) [edit]

### [edit] Helper classes

std::hash<std::bitset> (C++11) | hash support for std::bitset (class template specialization) [edit]

### [edit] Notes

If the size of the bitset is not known at compile time, std::vector<bool> or boost::dynamic_bitset may be used.

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/bitset&oldid=59501"