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

The `^` operator in Swift is the bitwise XOR (exclusive OR) operator. It performs a logical exclusive OR operation on the corresponding bits of two integer operands. The operator evaluates the binary representation of both values and returns a new integer where each bit is set to `1` if the corresponding bits of the operands differ, and `0` if they are identical.

## Bitwise Evaluation Logic

For any given bit position, the `^` operator applies the following truth table:

* `0 ^ 0` evaluates to `0`
* `0 ^ 1` evaluates to `1`
* `1 ^ 0` evaluates to `1`
* `1 ^ 1` evaluates to `0`

## Syntax and Execution

The operator requires both operands to be of the exact same type and must conform to the `BinaryInteger` protocol (e.g., `Int`, `UInt8`, `Int32`).

```swift theme={"dark"}
let lhs: UInt8 = 0b0011_1100  // Decimal 60
let rhs: UInt8 = 0b0000_1111  // Decimal 15

let result = lhs ^ rhs        // Evaluates to 0b0011_0011 (Decimal 51)
```

## Compound Assignment (`^=`)

Swift provides the `^=` compound assignment operator, which performs the bitwise XOR operation and assigns the result directly to the left-hand operand. The left-hand operand must be a mutable variable (`var`).

```swift theme={"dark"}
var bitPattern: UInt8 = 0b1010_1010
bitPattern ^= 0b1111_0000 

// bitPattern is mutated to 0b0101_1010
```

## Technical Constraints and Characteristics

* **Type Safety:** Swift enforces strict type safety. You cannot apply the `^` operator across mismatched integer types (e.g., `Int8` and `Int16`) without explicit casting.
* **Floating-Point Rejection:** The `^` operator cannot be applied to `Float`, `Double`, or `CGFloat` types. Bitwise operations in Swift are strictly reserved for integer bit patterns.
* **Operator Precedence:** The `^` operator belongs to the `AdditionPrecedence` group. In Swift's order of operations, it has lower precedence than the bitwise AND operator (`&`, which belongs to `MultiplicationPrecedence`), but shares the exact same precedence level as the bitwise OR operator (`|`), as well as standard addition (`+`) and subtraction (`-`). Because `^` and `|` share the same precedence group, they are evaluated left-to-right when chained together without parentheses.

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