Java Right Shift Operator
In this chapter you will learn:
- How to shift bits in a value to the right
- Syntax for Right Shift Operator
- Example - Right Shift Operator
Description
The right shift operator, >>
, shifts all of the bits in a value to the right a
specified number of times.
Syntax
Its general form is shown here:
value >> num
num
specifies the number of positions to right-shift.
Example
The following code fragment shifts the value 32
to the right by two positions:
public class Main {
public static void main(String[] argv) {
/* w w w. j a v a 2s . c om*/
int a = 32;
a = a >> 2;
System.out.println("a is " + a);
}
}
The output:
Next chapter...
What you will learn in the next chapter: