Shift Operators in Java
Last Updated : 19 Mar 2026
In Java, shift operators are a special type of operator that work on the bits of the data. These operators are used to shift the bits of the numbers from left to right or right to left, depending on the type of shift operator used. There are three types of shift operators in Java:
- Signed Left Shift Operator (<<)
- Signed Right Shift Operator (>>)
- Unsigned Right Shift Operator (>>>)
Note: Java does not support the unsigned left shift operator (<<< ).
| Operator | Operator Name | Uses | Description |
|---|---|---|---|
| << | Signed Left Shift Operator | a<<b | Shifts the first operand a number of bits to the left as specified in the second operand, shifting in 0s from the right. |
| >> | Signed Right Shift Operator | a>>b | Shifts the first operand a number of bits to the right as specified in the second operand and discards displaced bits. |
| >>> | Unsigned Right Shift Operator | a>>>b | Shifts the first operand a number of bits to the right as specified in the second operand, discards displaced bits and shifts in 0s from the left. |
Signed Left Shift Operator
The signed left shift operator is a special type of operator used to move the bits of the expression to the left according to the number specified after the operator.
Let's understand some examples to understand the working of the left shift operator.
Consider x =5.
Binary equivalent of 5 is 0101.

Assume that the statement is as follows:
x<<4, let y be 4

Let's implement the above logic in a Java program.
Example
Output:
The value is: 80
Signed Right Shift Operator
The signed right shift operator is a special type of operator used to move the bits of the expression to the right according to the number specified after the operator.
Let's understand some examples to understand the working of the right shift operator.
Consider x=80.
Binary equivalent of 80 is 1010000.

Assume that the statement is as follows:
x>>4, let y be 4

Let's implement the above logic in a Java program.
Example
Output:
The right-shifted value is: 5
Unsigned Right Shift Operator
The unsigned right shift operator is a special type of right shift operator that does not use the signal bit to fill in the sequence. The unsigned sign shift operator on the right always fills the sequence with 0.
Let's take the same example of the right-shift operator to understand the concept of the left-shift operator.
A negative number is the 2's complement of its positive number. So,
Thus x >>> 2 = 0000 0000 0000 0000 0000 0000 0000 1010
And y >>> 2 = 0011 1111 1111 1111 1111 1111 1111 0110
Example
Output:
The right sifted value of 40 by 5 is : 1 The right shifted value of -40 by 5 is : -2
Note: Unlike the unsigned Right Shift, there is no "<<<" operator in Java because the logical (<<) and arithmetic left-shift (<<<) operations are identical.
Important Points to Remember
- Left Shift (<<) Multiplies by Powers of 2: Shifting left by n positions (x << n) is equivalent to multiplying x by 2^n. Example: 5 << 4 is 5 * 2^4 = 80.
- Right Shift (>>) Divides by Powers of 2: Shifting right by n positions (x >> n) is equivalent to dividing x by 2^n, while keeping the sign intact. Example: 80 >> 4 is 80 / 2^4 = 5.
- Unsigned Right Shift (>>>) Fills with Zeroes: Unlike >>, which preserves the sign bit for negative numbers, >>> always fills with zeros.
- Negative Numbers and >>>: When using >>> on negative numbers, Java fills the leftmost bits with zeroes instead of sign extension, changing the result significantly. Example: -40 >>> 2 results in a large positive number.