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

# Swift Bitwise Left Shift Assignment

The `<<=` (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**

```swift theme={"dark"}
lhs <<= rhs
```

* `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.

**Technical Mechanics**

* **Equivalence:** The expression `a <<= b` is semantically identical to `a = a << b`.
* **Bit Manipulation:** Every bit in the memory layout of `lhs` is moved to the left (towards the most significant bit) by the number of positions specified by `rhs`.
* **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).

**Smart Shift Semantics**
Swift enforces "smart shift" behavior to safely handle edge cases in the `rhs` shift amount without trapping or causing fatal runtime errors:

* **Negative Shifts (Direction Reversal):** If the `rhs` shift 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 <<= -2` evaluates identically to `lhs >>= 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 by `bitWidth - 1`) rather than this directional reversal.
* **Overshifting:** If the `rhs` value is greater than or equal to the bit width of the `lhs` type, Swift safely resolves the over-shift to `0`. All original bits are shifted out of bounds and entirely replaced by zero-padding.

**Syntax Visualization**

```swift theme={"dark"}
// Initial memory state: 00000101 (Decimal 5)
var bitPattern: UInt8 = 0b0000_0101 

// Shift bits left by 3 positions and assign back
bitPattern <<= 3 

// Memory state: 00101000 (Decimal 40)
// The 3 rightmost bits are padded with 0s.
// The 3 leftmost bits are discarded.

// Negative shift behavior: safely reverses direction (right shift by 2)
bitPattern <<= -2 

// Memory state: 00001010 (Decimal 10)
// The operation performs a right shift by the absolute value (2).

// Overshift behavior: shifting by >= bitWidth results in 0
bitPattern <<= 8 

// Memory state: 00000000 (Decimal 0)
// All bits are shifted out of bounds.
```

<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 Swift 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>
