TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
| 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.
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 betweenbooltypes. - 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.
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.
Master Go with Deep Grasping Methodology!Learn More





