operatorstdbitset(3)
operator&,|,^(std::bitset) - operator&,|,^(std::bitset)
Synopsis
template <std::size_t N>
(1)
bitset<N>
operator&(const bitset<N> &lhs, const bitset<N> &rhs);
template <std::size_t N>
(2)
bitset<N>
operator|(const bitset<N> &lhs, const bitset<N> &rhs);
template <std::size_t N>
(3)
bitset<N>
operator^(const bitset<N> &lhs, const bitset<N> &rhs);Performs binary AND, OR, and XOR between two bitsets, lhs and rhs.
- Returns a bitset<N> containing the result of binary AND on corresponding pairs of bits of lhs and rhs.
- Returns a bitset<N> containing the result of binary OR on corresponding pairs of bits of lhs and rhs.
- Returns a bitset<N> containing the result of binary XOR on corresponding pairs of bits of lhs and rhs.
Parameters
lhs - the bitset on the left-hand side of the operator rhs - the bitset on the right-hand side of the operator
Return value
bitset<N>(lhs) &= rhs
bitset<N>(lhs) |= rhs
bitset<N>(lhs) ^= rhs
Exceptions
(none) (until C++11) noexcept specification: (since C++11) noexcept
Example
// Run this code #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:
See also
operator&= performs binary AND, OR, XOR and NOT
operator|= (public member function)
operator^=
operator~