Java Bitwise Right Shift
Java Bitwise Right Shift Operator is used to right shift a given value by specified number of bits.
Syntax
The syntax for Bitwise Right Shift operation between x
and y
operands is
</>
Copy
x >> y
The value of x
is right shifted by y
number of bits.
The operands can be of type int
or char
. Bitwise Right 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 right 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 Right-shift
int result = x >> y;
System.out.println("Result : " + result);
}
}
Output
Result : 12
Conclusion
In this Java Tutorial, we learned what Bitwise Right Shift Operator is, its syntax, and how to use this operator in Java programs, with the help of examples.