operator&,|,^(std::bitset)

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
 
Defined in header <bitset>
template< std::size_t N >

std::bitset<N> operator&( const std::bitset<N>& lhs,

                          const std::bitset<N>& rhs );
(1) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)
template< std::size_t N >

std::bitset<N> operator|( const std::bitset<N>& lhs,

                          const std::bitset<N>& rhs );
(2) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)
template< std::size_t N >

std::bitset<N> operator^( const std::bitset<N>& lhs,

                          const std::bitset<N>& rhs );
(3) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)

Performs binary AND, OR, and XOR between two bitsets, lhs and rhs.

1) Returns a std::bitset<N> containing the result of binary AND on corresponding pairs of bits of lhs and rhs.
2) Returns a std::bitset<N> containing the result of binary OR on corresponding pairs of bits of lhs and rhs.
3) Returns a std::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

1) std::bitset<N>(lhs) &= rhs
2) std::bitset<N>(lhs) |= rhs
3) std::bitset<N>(lhs) ^= rhs

Example

#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

See also

performs binary AND, OR, XOR and NOT
(public member function)