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

# Kotlin Bitwise OR

In Kotlin, the "or" operation is implemented via two distinct mechanisms: the `or` infix function, which performs bitwise operations on specific integral types and non-short-circuiting logical operations on booleans, and the `||` operator, which performs short-circuiting logical operations strictly on boolean expressions.

## The `or` Infix Function

The `or` identifier is a standard library function declared with the `infix` modifier. It is not a language keyword. It is overloaded to handle specific integral types and boolean types.

**Bitwise Evaluation (Integral Types)**
When applied to signed (`Int`, `Long`) or unsigned (`UInt`, `ULong`, `UShort`, `UByte`) integral types, `or` performs a bitwise inclusive OR operation. It compares each bit of the left-hand operand to the corresponding bit of the right-hand operand. If either bit is `1`, the resulting bit at that position is `1`. If both bits are `0`, the resulting bit is `0`.

*Note on Signed `Byte` and `Short`:* Kotlin does not define bitwise functions natively for signed `Byte` and `Short` types. To perform a bitwise OR on these types, they must be explicitly converted to `Int` first.

```kotlin theme={"dark"}
val a: Int = 0b0101 // Decimal: 5
val b: Int = 0b0011 // Decimal: 3

// Infix notation
val resultInfix: Int = a or b // Result: 0b0111 (Decimal: 7)

// Standard function call notation
val resultStandard: Int = a.or(b) 

// Signed Byte/Short require explicit conversion to Int
val byteA: Byte = 0b0101
val byteB: Byte = 0b0011
val byteResult: Int = byteA.toInt() or byteB.toInt()
```

**Non-Short-Circuiting Logical Evaluation (Boolean Type)**
When applied to `Boolean` types, `Boolean.or(Boolean)` performs a logical inclusive OR. Unlike the `||` operator, the `or` function does not short-circuit. Because it is a standard function call, both the left-hand and right-hand operands are strictly evaluated before the function is invoked, regardless of the left-hand operand's value.

```kotlin theme={"dark"}
val conditionA: Boolean = true
val conditionB: Boolean = false

// Both operands are evaluated before the 'or' function executes
val result: Boolean = conditionA or conditionB // Evaluates to true
```

**Precedence Note:**
Unlike languages such as Java or C++ where bitwise AND (`&`) has higher precedence than bitwise OR (`|`), Kotlin implements these as standard infix functions. All infix functions share the exact same precedence level. Therefore, chained infix operations evaluate strictly left-to-right unless explicitly grouped with parentheses.

```kotlin theme={"dark"}
// Evaluates strictly left-to-right: (1 or 4) and 2
// Step 1: 1 or 4  -> 0b0001 | 0b0100 = 0b0101 (5)
// Step 2: 5 and 2 -> 0b0101 & 0b0010 = 0b0000 (0)
val chainedResult = 1 or 4 and 2 // Result: 0

// Note: If 'and' had higher precedence, this would evaluate as 1 or (4 and 2) -> 1 or 0 -> 1
```

## The Logical `||` Operator

The `||` operator performs a logical inclusive OR operation exclusively on `Boolean` expressions. It evaluates to `true` if at least one of its operands evaluates to `true`. If both operands evaluate to `false`, the expression returns `false`.

**Short-Circuit Evaluation:**
The `||` operator is lazily evaluated. The left-hand operand is evaluated first. If it resolves to `true`, the overall expression is guaranteed to be `true`, and the right-hand operand is completely bypassed. The right-hand operand is evaluated if and only if the left-hand operand resolves to `false`.

```kotlin theme={"dark"}
fun isTrue(): Boolean = true
fun isFalse(): Boolean = false

// isFalse() is never executed because the left operand resolves to true
val result: Boolean = isTrue() || isFalse() 
```

**Precedence Note:**
The logical `||` operator has lower precedence than the logical AND operator (`&&`).

```kotlin theme={"dark"}
// Evaluates as false || (true && false) -> false || false -> false
val logicalResult = false || true && false 
```

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