Namespaces
Variants
Views
Actions

std::bitset::operator<<,<<=,>>,>>=

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

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

<td >
bitset<N> operator<<( size_t pos ) const;
</td>

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

<td >
bitset<N>& operator<<=( size_t pos );
</td>

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

<td >
bitset<N> operator>>( size_t pos ) const;
</td>

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

<td >
bitset<N>& operator>>=( size_t pos );
</td>

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

Performs binary shift left and binary shift right. Zeroes are shifted in.

1-2) Performs binary shift left. The (2) version is destructive, i.e. performs the shift to the current object.

3-4) Performs binary shift right. The (4) version is destructive, i.e. performs the shift to the current object.

Contents

Parameters

pos - number of positions to shift the bits

Return value

1,3) new bitset object containing the shifted bits

2,4) *this

Example

#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<8> b("01110010");
    std::cout << "initial value: " << b << '\n';
 
    while (b.any()) {
        while (!b.test(0)) {
            b >>= 1;
        }
        std::cout << b << '\n';
        b >>= 1;
    }
}

Output:

initial value: 01110010
00111001
00000111
00000011
00000001

See also

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