Number.BitwiseOr
NumberPerforms a bitwise OR operation on two integer values.
Syntax
Number.BitwiseOr(number1 as number, number2 as number) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
number1 | number | Yes | The first integer operand. |
number2 | number | Yes | The second integer operand. |
Return Value
number — An integer where each bit is 1 if the corresponding bit is 1 in either input.
Remarks
Number.BitwiseOr performs a bitwise OR between two integers. Each bit position in the result is 1 when the corresponding bit is 1 in at least one of the operands; it is 0 only when both operands have 0 at that position. Both inputs are treated as integers — fractional parts are truncated.
Bitwise OR is most commonly used to set bits (turn specific bits on) or merge bitmasks. Unlike AND (which tests/extracts bits), OR ensures that bits are added to a value. A value ORed with a mask will always have at least the mask's bits set.
Common patterns:
- Combine flags: Number.BitwiseOr(flags, 4) sets bit 2 in flags regardless of its current state
- Merge permission sets: OR-ing two permission integers gives the union of all permitted capabilities
- Reconstruct packed values: building an integer from separate bit-field contributions by OR-ing shifted components
Note that Number.BitwiseOr(x, x) = x (idempotent) and Number.BitwiseOr(x, 0) = x (OR with 0 is identity).
Examples
Example 2: Set bit 0 (value 1) in a number that doesn't have it
Number.BitwiseOr(12, 1)Result | |
|---|---|
| 1 | 13 |
Example 3: Combine permission flags (Read=1, Write=2, Execute=4)
let
Read = 1,
Write = 2,
Execute = 4,
ReadWrite = Number.BitwiseOr(Read, Write),
AllPerms = Number.BitwiseOr(ReadWrite, Execute)
in
#table({"ReadWrite", "AllPerms"}, {{ReadWrite, AllPerms}})The final output — a single-row table showing ReadWrite = 3 and AllPerms = 7.
ReadWrite | AllPerms | |
|---|---|---|
| 1 | 3 | 7 |