> ## 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 AND Assignment

The `&=` operator is the bitwise AND assignment operator in Swift. It performs a bitwise AND operation between the binary representations of two integer operands and immediately assigns the resulting value to the left-hand operand. It serves as a syntactic shorthand, where `a &= b` is strictly equivalent to `a = a & b`.

## Syntax

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

* **`lhs`**: A mutable variable (`var`) conforming to a bitwise protocol (typically `BinaryInteger`).
* **`rhs`**: An expression of the exact same type as `lhs`.

## Mechanics

The operator evaluates the operands bit by bit. For each corresponding position in the binary representation, the resulting bit is set to `1` if and only if both the `lhs` bit and the `rhs` bit are `1`. Otherwise, the resulting bit is set to `0`.

| `lhs` bit | `rhs` bit | Resulting `lhs` bit |
| :-------- | :-------- | :------------------ |
| `1`       | `1`       | `1`                 |
| `1`       | `0`       | `0`                 |
| `0`       | `1`       | `0`                 |
| `0`       | `0`       | `0`                 |

## Code Visualization

```swift theme={"dark"}
var a: UInt8 = 0b1100_1010 // Decimal: 202
let b: UInt8 = 0b1010_1111 // Decimal: 175

a &= b 

// Evaluation process:
//   11001010 (a)
// & 10101111 (b)
// -------
//   10001010 (Result assigned to a)

print(String(a, radix: 2)) // Prints: 10001010
print(a)                   // Prints: 138
```

## Technical Constraints

1. **Type Strictness**: Swift's strong type system dictates that both operands must be of the exact same type. You cannot apply `&=` between a `UInt8` and a `UInt16` without explicit casting.
2. **Mutability**: Because this is an assignment operator, the left-hand operand must be mutable. Attempting to use `&=` on a `let` constant will result in a compile-time error.
3. **Operator Overloading**: The `&=` operator can be implemented for custom types. To do so, you define a `static func &= (lhs: inout CustomType, rhs: CustomType)` method within the type's definition or extension. Types conforming to the `BinaryInteger` protocol receive this operator by default.

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