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, 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, always padding the high-order empty bit positions with zeros. Unlike the standard right shift operator (>>), which performs an arithmetic shift on signed integer types (preserving the sign bit by padding with 1s for negative numbers), the >>> operator strictly performs a logical shift. It ignores the sign bit of the original value and unconditionally shifts zeros into the most significant bit (MSB) positions, regardless of whether the operand’s type is signed (int, long, sbyte, short) or unsigned (uint, ulong, byte, ushort).
result = expression >>> count;

Mechanical Behavior

1. Zero Padding When shifting a negative signed integer, the >>> operator forces a zero into the MSB, effectively changing the sign of the resulting value to positive. For unsigned types, >>> and >> produce identical results.
int x = -8; 
// 32-bit binary: 11111111 11111111 11111111 11111000

int arithmeticShift = x >> 2;
// Result: -2
// 32-bit binary: 11111111 11111111 11111111 11111110 (Padded with 1s)

int logicalShift = x >>> 2;
// Result: 1073741822
// 32-bit binary: 00111111 11111111 11111111 11111110 (Padded with 0s)
2. Shift Count Masking The actual number of bits shifted is determined by masking the right-hand operand (count) to prevent shifting by more bits than the type contains:
  • For 32-bit operands (int, uint), the shift count is evaluated as count & 0x1F (equivalent to count % 32).
  • For 64-bit operands (long, ulong), the shift count is evaluated as count & 0x3F (equivalent to count % 64).
3. Numeric Promotion If the left-hand operand is a type smaller than 32 bits (sbyte, byte, short, ushort), C# implicitly promotes it to an int before performing the shift operation. The result of the >>> operation will therefore be an int.
sbyte a = -16;
// Promoted to int: 11111111 11111111 11111111 11110000

var result = a >>> 4; 
// Type is int. Result: 268435455
// Binary: 00001111 11111111 11111111 11111111

Compound Assignment

The operator supports compound assignment via >>>=. This evaluates the shift and assigns the result back to the left-hand variable in a single operation.
int value = -100;
value >>>= 3; 
Master C# with Deep Grasping Methodology!Learn More