bitOr

x | y

bitOr(x, y)

Try it yourself:


bitOr(): set bits from either value

bitOr(a, b) performs a bitwise OR: each result bit is 1 when either input has a 1 in that position. bitOr(12, 10) combines 1100 and 1010 into 1110, or 14.

Combining flags

OR is the usual operation for building a flag set. If read permission is 1 and write permission is 2, bitOr(1, 2) creates the value 3 containing both. It does not remove bits already present, so it is ideal for enabling options.

Related bit operations

Inspect masks with bin(). Test whether a flag is present with bitAnd(), toggle it with bitXor(), and invert a mask with bitNot(). For hexadecimal notation, see hex().

Input caveat

Use integer operands. Negative values are valid under signed integer semantics but are harder to read because their high sign bits are set; document the intended width when values cross a system boundary.

All functions