Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | utility‎ | bitset
Revision as of 15:01, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
bitset<N> operator&( const bitset<N>& lhs, const bitset<N>& rhs );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
bitset<N> operator|( const bitset<N>& lhs, const bitset<N>& rhs );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
bitset<N> operator^( const bitset<N>& lhs, const bitset<N>& rhs );
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

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

1) Returns a bitset<N> containing the result of binary AND on corresponding pairs of bits of lhs and rhs.

2) Returns a bitset<N> containing the result of binary OR on corresponding pairs of bits of lhs and rhs.

3) Returns a bitset<N> containing the result of binary XOR on corresponding pairs of bits of lhs and rhs.

Contents

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) bitset<N>(lhs) &= rhs

2) bitset<N>(lhs) |= rhs

3) bitset<N>(lhs) ^= rhs

Exceptions

noexcept specification:  
noexcept
  

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) [edit]