Java Bitwise Left Shift
Java 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
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.java
</>
Copy
public class Main {
public static void main(String[] args) {
int x = 49;
int y = 2;
//Bitwise Left-shift
int result = x << y;
System.out.println("Result : " + result);
}
}
Output
Result : 196
Conclusion
In this Java Tutorial, we learned what Bitwise Left Shift Operator is, its syntax, and how to use this operator in Java programs, with the help of examples.