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

# C# Unsigned Right Shift Assignment

The `>>>=` operator is the **unsigned right-shift assignment operator**, introduced in C# 11. It shifts the bits of its left-hand operand to the right by the number of positions specified by its right-hand operand, fills the vacated high-order bit positions with zeros (a logical shift), and assigns the resulting value back to the left-hand operand.

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

At compile time, this compound assignment is evaluated as:

```csharp theme={"dark"}
leftOperand = (T)(leftOperand >>> rightOperand);
```

where `T` is the type of `leftOperand`.

Crucially, C# semantic rules dictate that `leftOperand` is **evaluated only once**. This is an important distinction from the expanded form when the left operand contains side effects. For example, in the expression `array[i++] >>>= 2;`, the index `i` is incremented only a single time.

## Mechanical Behavior

The defining characteristic of the `>>>=` operator is that it strictly performs a **logical shift** (zero-extension), regardless of whether the left-hand operand is a signed or unsigned integer type.

By contrast, the standard right-shift assignment operator (`>>=`) performs an **arithmetic shift** (sign-extension) on signed integer types, copying the most significant bit (the sign bit) into the vacated positions to preserve the sign of the number. `>>>=` ignores the sign bit and always shifts in `0`.

## Shift Count Masking

To prevent undefined behavior from oversized shift counts, C# masks the right-hand operand based on the bit-width of the left-hand operand (after any implicit numeric promotion):

* **32-bit types** (`int`, `uint`): The shift count is determined by the lowest 5 bits of the right-hand operand (`rightOperand & 0x1F`). The actual shift is always between 0 and 31.
* **64-bit types** (`long`, `ulong`): The shift count is determined by the lowest 6 bits of the right-hand operand (`rightOperand & 0x3F`). The actual shift is always between 0 and 63.

## Syntax Visualization

The following example demonstrates the mechanical difference between arithmetic (`>>=`) and logical (`>>>=`) right-shift assignments on a signed 32-bit integer.

```csharp theme={"dark"}
int x = -8; 
// 32-bit binary: 11111111 11111111 11111111 11111000

// Arithmetic right-shift assignment (sign-extension)
x >>= 2;    
// 32-bit binary: 11111111 11111111 11111111 11111110
// Decimal value: -2

int y = -8;
// 32-bit binary: 11111111 11111111 11111111 11111000

// Unsigned right-shift assignment (zero-extension)
y >>>= 2;   
// 32-bit binary: 00111111 11111111 11111111 11111110
// Decimal value: 1073741822
```

## Type Support and Overloading

* **Built-in Support:** The operator is natively supported for `int`, `uint`, `long`, `ulong`, `nint`, and `nuint`. When applied to smaller integral types (`byte`, `sbyte`, `short`, `ushort`), the operands are implicitly promoted to `int` before the shift operation. Because compound assignment operators automatically apply an explicit cast back to the target type, statements like `byte b = 8; b >>>= 2;` compile and execute successfully without requiring the developer to write an explicit cast.
* **Overloadability:** User-defined types can overload the `>>>` operator. When a custom type overloads `>>>`, the `>>>=` operator is implicitly overloaded as well. You cannot explicitly overload `>>>=`.

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