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.
<<= (Bitwise Left Shift Assignment) operator is a compound assignment operator that shifts the binary representation of a mutable integer variable to the left by a specified number of bits, immediately assigning the computed result back to the original variable. It combines the bitwise left shift operation (<<) with the assignment operation (=).
Syntax
lhs: A mutable variable (var) of an integer type (e.g.,Int,UInt8).rhs: An integer expression representing the number of bit positions to shift.
- Equivalence: The expression
a <<= bis semantically identical toa = a << b. - Bit Manipulation: Every bit in the memory layout of
lhsis moved to the left (towards the most significant bit) by the number of positions specified byrhs. - Padding: As bits are shifted left, the vacated bit positions on the right (the least significant bits) are strictly filled with zeros.
- Truncation: Any bits shifted beyond the maximum bounds of the integer type’s allocated bit width are permanently discarded (dropped).
rhs shift amount without trapping or causing fatal runtime errors:
- Negative Shifts (Direction Reversal): If the
rhsshift amount is negative, Swift safely handles the operation by reversing the shift direction. A negative left shift is executed as a right shift by the absolute value of the amount (e.g.,lhs <<= -2evaluates identically tolhs >>= 2). Developers only need to use the masking left shift assignment operator (&<<=) if they specifically require C-like masking behavior (where the negative shift amount is masked bybitWidth - 1) rather than this directional reversal. - Overshifting: If the
rhsvalue is greater than or equal to the bit width of thelhstype, Swift safely resolves the over-shift to0. All original bits are shifted out of bounds and entirely replaced by zero-padding.
Master Swift with Deep Grasping Methodology!Learn More





