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

# Go Bitwise OR

The `|` operator in Go is the bitwise OR operator. It performs a logical inclusive OR operation on each pair of corresponding bits of two integer operands. If either or both bits in the compared position are `1`, the resulting bit is `1`; otherwise, it evaluates to `0`.

```go theme={"dark"}
result := operand1 | operand2
```

## Bit-Level Evaluation

The operator evaluates the binary representation of the operands using the following truth table for each bit position:

| Bit A | Bit B | Result (A \| B) |
| :---: | :---: | :-------------: |
|   0   |   0   |      **0**      |
|   0   |   1   |      **1**      |
|   1   |   0   |      **1**      |
|   1   |   1   |      **1**      |

## Type Constraints

In Go, the `|` operator is strictly constrained to integer types (e.g., `int`, `uint8`, `int32`, `byte`, `rune`).

* It cannot be applied to floating-point numbers (`float32`, `float64`), complex numbers, or strings.
* It cannot be used for boolean logic; Go uses the `||` operator for logical OR operations between `bool` types.
* Both operands must resolve to the same integer type. If the operands are typed variables of different integer types, an explicit type conversion (e.g., `uint8(b)`) is required prior to the operation. However, an untyped integer constant (e.g., `12`) can be used directly with a typed integer variable, as the Go compiler implicitly converts the untyped constant to the variable's type.

## Mechanical Example

The following example demonstrates how the `|` operator processes the underlying binary values of two `uint8` integers.

```go theme={"dark"}
package main

import "fmt"

func main() {
    var a uint8 = 10 // Binary representation: 00001010
    var b uint8 = 12 // Binary representation: 00001100

    // Bitwise OR operation
    result := a | b  // Binary representation: 00001110 (Decimal: 14)

    fmt.Printf("a:      %08b\n", a)
    fmt.Printf("b:      %08b\n", b)
    fmt.Printf("result: %08b\n", result)
}
```

**Execution Trace:**

```text theme={"dark"}
  00001010  (a)
| 00001100  (b)

  00001110  (result)
```

## Compound Assignment

Go also supports the bitwise OR assignment operator (`|=`), which applies the bitwise OR operation to a variable and assigns the result back to that same variable in a single statement.

```go theme={"dark"}
var a uint8 = 10
var b uint8 = 12

a |= b // Syntactic sugar for: a = a | b
```

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