C++ <bitset> - operator<< Function
The C++ bitset::operator<< function is used to perform bitwise left SHIFT operation on the given bitset.
Syntax
bitset operator<<(size_t pos) const;
bitset operator<<(size_t pos) const noexcept;
Parameters
pos |
Specify number of bit locations to be shifted. |
Return Value
Returns new bitset object which contains shifted bits.
Exception
Never throws exceptions.
Example:
In the example below, the bitset::operator<< function is used to perform bitwise left SHIFT operation on the given bitset.
#include <iostream> #include <bitset> using namespace std; int main (){ bitset<4> bset("1001"); cout<<"bset is: "<<bset; //performing bitwise left shift operation using bset cout<<"\n(bset<<1): "<<(bset<<1); cout<<"\n(bset<<2): "<<(bset<<2); return 0; }
The output of the above code will be:
bset is: 1001 (bset<<1): 0010 (bset<<2): 0100
❮ C++ <bitset> Library