TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
&>>= operator is the masking bitwise right shift assignment operator. It shifts the binary representation of the left-hand operand to the right by a specified number of positions, masks the shift amount to prevent runtime overflow traps, and assigns the computed result back to the left-hand operand.
Mechanics
1. Shift Amount Masking Standard shift operators (like>>=) will trigger a runtime panic if the right-hand operand (rhs) is greater than or equal to the bit width of the left-hand operand (lhs), or if it is negative. The &>>= operator prevents this by masking rhs against (lhs.bitWidth - 1).
For an 8-bit integer (Int8 or UInt8), the mask is 7 (0b0111). If you attempt to shift an 8-bit integer right by 11 positions (0b1011), the operator applies the mask (11 & 7 = 3) and performs a shift of exactly 3 positions.
2. Logical vs. Arithmetic Shifting
The behavior of the shifted bits depends on the signedness of the left-hand operand’s type:
- Unsigned Types (
UInt,UInt8, etc.): Performs a logical right shift. The bits are shifted right, and the vacated bit positions on the most significant (left) side are filled with zeros. - Signed Types (
Int,Int8, etc.): Performs an arithmetic right shift. The bits are shifted right, but the vacated bit positions are filled with the original sign bit (the most significant bit). This preserves the sign of the integer (zeros for positive numbers, ones for negative numbers).
Syntax Visualization
Master Swift with Deep Grasping Methodology!Learn More





