C++ Standard Library C++ STL Library

C++ <bitset> - operator<<= Function



The C++ bitset::operator<<= function is used to perform bitwise left SHIFT operation on the current bitset object.

Syntax

bitset& operator<<= (size_t pos);
bitset& operator<<= (size_t pos) noexcept;

Parameters

pos Specify number of bit locations to be shifted.

Return Value

*this

Exception

Never throws exceptions.

Example:

In the example below, the bitset::operator<<= function is used to perform bitwise left SHIFT operation on the current bitset object.

#include <iostream>
#include <bitset>
using namespace std;
 
int main (){
  bitset<4> bset("1001");

  cout<<"bset is: "<<bset;

  //performing bitwise left shift operation on bset
  bset<<=2;
  cout<<"\n(bset<<2): "<<bset;

  return 0;
}

The output of the above code will be:

bset is: 1001
(bset<<2): 0100

❮ C++ <bitset> Library