> ## 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.

# Java Right Shift Assignment

The `>>=` (signed right shift assignment) operator is a compound assignment operator that shifts the binary representation of the left operand to the right by a specified number of bits, performs sign extension, and assigns the resulting value back to the left operand.

## Syntax

```java theme={"dark"}
leftOperand >>= rightOperand;
```

This operation is logically equivalent to:

```java theme={"dark"}
leftOperand = (Type) (leftOperand >> rightOperand);
```

## Bitwise Mechanics

**1. Sign Extension**
Unlike the unsigned right shift (`>>>=`), the `>>=` operator preserves the sign of the original value by inspecting the Most Significant Bit (MSB).

* If the left operand is positive (MSB is `0`), the vacated leftmost bits are padded with `0`s.
* If the left operand is negative (MSB is `1`), the vacated leftmost bits are padded with `1`s.

**2. Bit Discarding**
Bits shifted to the right beyond the Least Significant Bit (LSB) are permanently discarded.

**3. Shift Distance Masking**
Java limits the shift distance based on the data type of the left operand to prevent out-of-bounds shifts:

* **`int` operands:** The right operand is implicitly masked with `0x1F` (bitwise AND with 31). For example, `x >>= 33` is executed as `x >>= 1`.
* **`long` operands:** The right operand is implicitly masked with `0x3F` (bitwise AND with 63). For example, `y >>= 65` is executed as `y >>= 1`.

**4. Implicit Narrowing Conversion**
When used with types smaller than `int` (`byte`, `short`, `char`), the left operand is first promoted to an `int` for the shift operation. The compound assignment operator then automatically applies an implicit cast to narrow the result back to the original type. This prevents the compilation errors that would normally occur when assigning an `int` result back to a smaller integral type.

## Execution Examples

**Positive Integer Shift**

```java theme={"dark"}
int a = 20;       // Binary: 00000000 00000000 00000000 00010100
a >>= 2;          // Shifts right by 2, pads with 0s
// Result: 5      // Binary: 00000000 00000000 00000000 00000101
```

**Negative Integer Shift**

```java theme={"dark"}
int b = -20;      // Binary: 11111111 11111111 11111111 11101100
b >>= 2;          // Shifts right by 2, pads with 1s (sign extension)
// Result: -5     // Binary: 11111111 11111111 11111111 11111011
```

**Implicit Casting with Byte**

```java theme={"dark"}
byte c = -128;    // Binary: 10000000 (promoted to int: 1111...10000000)
c >>= 1;          // Shifts right by 1, pads with 1s, implicitly casts back to byte
// Result: -64    // Binary: 11000000
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
