std::bitset::operator[]
From cppreference.com
bool operator[]( size_t pos ) const; |
(1) | |
reference operator[]( size_t pos ); |
(2) | |
Accesses the bit at position pos. The first version returns the value of the bit, the second version returns an object of type std::bitset::reference that allows modification of the value.
Throws std::out_of_range if pos does not correspond to a valid bit position.
Contents |
[edit] Parameters
pos | - | position of the bit to return |
[edit] Return value
1) the value of the requested bit
2) an object of type std::bitset::reference with the value of the bit.
[edit] Example
#include <iostream> #include <bitset> int main() { std::bitset<8> b1(42); for (int i = 0; i < b1.size(); ++i) { std::cout << "b1[" << i << "]: " << b1[i] << '\n'; } return 0; }
Output:
b1[0]: 0 b1[1]: 1 b1[2]: 0 b1[3]: 1 b1[4]: 0 b1[5]: 1 b1[6]: 0 b1[7]: 0
[edit] See also
accesses specific bit (public member function) |