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

The `|` operator in Swift is the bitwise OR operator. It performs a logical inclusive OR operation on the individual binary bits of two integer values. It evaluates the operands bit-by-bit and returns a new integer of the same type, where each bit is set to `1` if the corresponding bit in *either* or *both* of the operands is `1`. If both corresponding bits are `0`, the resulting bit is `0`.

## Syntax

The operator is an infix operator placed between two integer operands of the exact same type.

```swift theme={"dark"}
let result = operand1 | operand2
```

## Bitwise Evaluation Mechanics

The operator follows a standard truth table for each bit position:

* `0 | 0` evaluates to `0`
* `0 | 1` evaluates to `1`
* `1 | 0` evaluates to `1`
* `1 | 1` evaluates to `1`

## Code Visualization

To observe the mechanical behavior, it is best to use explicitly typed unsigned integers (like `UInt8`) and binary literals (`0b` prefix).

```swift theme={"dark"}
let a: UInt8 = 0b10100011 // Decimal: 163
let b: UInt8 = 0b01011010 // Decimal: 90

let c = a | b             // Decimal: 251
```

**Bit-by-bit execution:**

```text theme={"dark"}
  10100011  (Operand a)
| 01011010  (Operand b)

  11111011  (Result c)
```

## Type Constraints

Swift enforces strict type safety. The `|` operator cannot implicitly bridge different integer types or sizes. Both operands must be of the exact same type, and the return type will match the operands.

```swift theme={"dark"}
let x: UInt8 = 0b00001111
let y: UInt16 = 0b11110000

// let z = x | y // Compiler Error: Binary operator '|' cannot be applied to operands of type 'UInt8' and 'UInt16'
let z = UInt16(x) | y // Valid: Both are now UInt16
```

## Compound Assignment

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

```swift theme={"dark"}
var register: UInt8 = 0b00000000
register |= 0b00001111 
// register is now 0b00001111

register |= 0b11110000 
// register is now 0b11111111
```

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