C++ Bitset Library - operator<< Function


Advertisements


Description

The C++ function std::bitset::operator<< performs bitwise left SHIFT operation on bitset.

Declaration

Following is the declaration for std::bitset::operator<< function form std::bitset header.

C++98

bitset operator<<(size_t pos) const;

C++11

bitset operator<<(size_t pos) const noexcept;

Parameters

pos − Number of bits to be shifted.

Return value

Returns new bitset object which contains shifted bits.

Exceptions

This member function never throws exception.

Example

The following example shows the usage of std::bitset::operator<< function.

Live Demo
#include <iostream>
#include <bitset>

using namespace std;

int main(void) {

   bitset<4> b("0001");

   auto result = b << 1;

   cout << result << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

0010

bitset.htm

Advertisements