Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The >>> operator is the unsigned right shift operator (also known as the logical right shift operator) in Java. It shifts the bit pattern of the left operand to the right by the number of positions specified by the right operand, strictly filling the vacated leftmost bits with zeros (0). This behavior ignores the original sign bit of the value, distinguishing it from the signed right shift operator (>>), which performs sign-extension.
result = value >>> distance;

Operand Mechanics and Type Promotion

  • value (Left Operand): Must be an integral type. If the operand is a byte, short, or char, Java performs implicit widening primitive conversion, promoting it to a 32-bit int before the shift operation occurs.
  • distance (Right Operand): Specifies the number of bit positions to shift. To prevent over-shifting, Java applies a bitwise AND mask to the right operand based on the type of the left operand:
    • If the left operand evaluates to an int, the shift distance is masked with 0x1F (distance & 31).
    • If the left operand evaluates to a long, the shift distance is masked with 0x3F (distance & 63).

Bitwise Execution

When value >>> distance is evaluated:
  1. The bits of value are moved to the right by distance steps.
  2. The bits shifted off the right boundary (least significant bits) are discarded.
  3. The distance number of vacant bit positions on the left boundary (most significant bits) are populated with 0 (zero-extension).

Syntax Visualization

The mechanical distinction of >>> is most apparent when applied to negative integers, where the most significant bit (MSB) is 1.
int negativeValue = -8; 
// 32-bit binary: 11111111 11111111 11111111 11111000

int result = negativeValue >>> 2; 
// Shift right by 2, fill left with 00
// 32-bit binary: 00111111 11111111 11111111 11111110
// Decimal result: 1073741822

Contrast with Signed Right Shift (>>)

For positive numbers, >>> and >> yield identical results because the MSB is already 0. For negative numbers, >> fills the vacated left bits with 1s to preserve the negative sign (sign-extension), whereas >>> forces 0s, resulting in a positive integer.
int val = -8;

// Signed Right Shift
System.out.println(val >> 2);  
// Output: -2         (Binary: 11111111 11111111 11111111 11111110)

// Unsigned Right Shift
System.out.println(val >>> 2); 
// Output: 1073741822 (Binary: 00111111 11111111 11111111 11111110)
Master Java with Deep Grasping Methodology!Learn More