Namespaces
Variants
Views
Actions

std::bitset::operator&=,|=,^=,~

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

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

<td >
bitset<N>& operator&=( const bitset<N>& other );
</td>

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

<td >
bitset<N>& operator|=( const bitset<N>& other );
</td>

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

<td >
bitset<N>& operator^=( const bitset<N>& other );
</td>

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

<td >
bitset<N> operator~() const;
</td>

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

Performs binary AND, OR, XOR and NOT.

1) Sets the bits to the result of binary AND on corresponding pairs of bits of *this and other.

2) Sets the bits to the result of binary OR on corresponding pairs of bits of *this and other.

3) Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and other.

4) Returns a temporary copy of *this with all bits flipped (binary NOT).

Note that &=, |=, and ^= are only defined for bitsets of the same size N.

Contents

Parameters

other - another bitset

Return value

1-3) *this

4) a bitset<N> temporary with all bits flipped

Example

#include <iostream>
#include <string>
#include <bitset>
 
int main()
{
    std::bitset<16> dest;
    std::string pattern_str = "1001";
    std::bitset<16> pattern(pattern_str);
 
    for (size_t i = 0, ie = dest.size()/pattern_str.size(); i != ie; ++i) {
        dest <<= pattern_str.size();
        dest |= pattern;
    }
    std::cout << dest << '\n';
}

Output:

1001100110011001

See also

performs binary shift left and shift right
(public member function) [edit]