In this tutorial, you shall learn about Bitwise Left Shift Operator in C++ programming language, its syntax, and how to use this operator with the help of examples.

C++ Bitwise Left Shift

C++ Bitwise Left Shift Operator is used to left shift a given value by specified number of bits.

Syntax

The syntax for Bitwise Left Shift operation between x and y operands is

</>
Copy
x << y

The value of x is left shifted by y number of bits.

The operands can be of type int or char. Bitwise Left Shift operator returns a value of type same as that of the given operands.

Examples

1. Bitwise left shift of x=5 by 3 bits

In the following example, we take two integer values in x and y, and find the left shift of x by y number of bits.

main.cpp

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int x = 5;
    int y = 3;
    int result = x << y;
    cout << "Result : " << result << endl;
}

Output

Result : 40
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned what Bitwise Left Shift Operator is, its syntax, and how to use this operator in C++ programs, with the help of examples.