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.

Try Bit Or in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions