bitset::operator<<

將 bitset 的位元向左移位置的指定數目並將結果傳回新的 bitset。

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

參數

  • _Pos
    位置左邊的要在 bitset 位元移位。

傳回值

使用位元的修訂 bitset 會向左移位位置所需數目。

備註

成員運算子函式傳回 bitset(*this) <<= pos,<<= 將 bitset 的位元向左移位置的指定數目並將結果傳回目標的 bitset 的位置。

範例

// bitset_op_LS.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;
}

Output

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 ).

需求

標題: <bitset>

命名空間: std

請參閱

參考

bitset Class