Language syntax

Integer shift operators

Shifts the promoted left operand. Right shift >> preserves the sign bit, while >>> fills with zero. Shift distances are masked to 5 bits for int and 6 bits for long. Syntax shows alternatives.

Formal Syntax & Structure

java syntaxjava
value << distance; value >> distance; value >>> distance

Working Example

Example Snippetjava
public class Main {    public static void main(String[] args) {        System.out.println(-4 >> 1);        System.out.println(-4 >>> 1);        System.out.println(1L << 40);    }}
Java Reference