template< std::size_t N > bitset<N> operator&( const bitset<N>& lhs, const bitset<N>& rhs ); | (1) | |
template< std::size_t N > bitset<N> operator|( const bitset<N>& lhs, const bitset<N>& rhs ); | (2) | |
template< std::size_t N > bitset<N> operator^( const bitset<N>& lhs, const bitset<N>& rhs ); | (3) |
Performs binary AND, OR, and XOR between two bitsets, lhs
and rhs
.
bitset<N>
containing the result of binary AND on corresponding pairs of bits of lhs
and rhs
.bitset<N>
containing the result of binary OR on corresponding pairs of bits of lhs
and rhs
.bitset<N>
containing the result of binary XOR on corresponding pairs of bits of lhs
and rhs
.lhs | - | the bitset on the left-hand side of the operator |
rhs | - | the bitset on the right-hand side of the operator |
bitset<N>(lhs) &= rhs
bitset<N>(lhs) |= rhs
bitset<N>(lhs) ^= rhs
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
#include <bitset> #include <iostream> int main() { std::bitset<4> b1("0110"); std::bitset<4> b2("0011"); std::cout << "b1 & b2: " << (b1 & b2) << '\n'; std::cout << "b1 | b2: " << (b1 | b2) << '\n'; std::cout << "b1 ^ b2: " << (b1 ^ b2) << '\n'; }
Output:
b1 & b2: 0010 b1 | b2: 0111 b1 ^ b2: 0101
performs binary AND, OR, XOR and NOT (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/bitset/operator_logic2