bitset::operator>>

Shifts the bits in a bitset to the right a specified number of positions and returns the result to a new bitset.

bitset<N> operator>>(
   size_t _Pos
) const;

Parameters

  • _Pos
    The number of positions to the right the bits in the bitset are to be shifted.

Return Value

A new bitset where the bits have been shifted to the right the required number of positions relative to the targeted bitset.

Example

// bitset_op_RS.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
   using namespace std;
   bitset<5> b1 ( 7 );
   cout << "The bitset b1 is: ( "<< b1 << " )." << endl;

   bitset<5> b2;
   b2 = b1 << 2;

   cout << "After shifting the bits 2 positions to the left,\n"
        << " the bitset b2 is: ( "<< b2 << " )."
        << endl;
   bitset<5> b3 = b2 >> 1;

   cout << "After shifting the bits 1 position to the right,\n"
        << " the bitset b3 is: ( " << b3 << " )."
        << endl;
}
The bitset b1 is: ( 00111 ).
After shifting the bits 2 positions to the left,
 the bitset b2 is: ( 11100 ).
After shifting the bits 1 position to the right,
 the bitset b3 is: ( 01110 ).

Requirements

Header: <bitset>

Namespace: std

See Also

Reference

bitset Class

Other Resources

bitset Members