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 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.
leftOperand >>>= rightOperand;
At compile time, this compound assignment is evaluated as:
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.
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 >>>=.
Master C# with Deep Grasping Methodology!Learn More