Expand/Shrink

or_bits

Definition: atom x3 = or_bits(atom x1, atom x2)
Description: Perform the logical OR operation on corresponding bits in x1 and x2.
A bit in x3 will be 1 when a corresponding bit in either x1 or x2 is 1.

Commonly used to set bits in a bit-field (see example 1).
pwa/p2js: Supported.
Comments: As of 0.8.2+ the infix operator || can be used in place of or_bits().

This function may be applied to an atom or sq_or_bits() to all elements of a sequence.
The rules for sequence operations apply.

The arguments must be representable as 32-bit numbers, either signed or unsigned.

If you intend to manipulate full 32-bit values, you should declare your variables as atom, rather than integer. The integer type is limited to 31-bits.

Results are treated as signed numbers. They will be negative when the highest-order bit is 1.

Caution: many cryptographic functions and the like require unsigned 32-bit integers, especially when bit-shifting, for which or_bitsu() can be used instead.
Example 1:
flags = or_bits(flags,XPAD) -- apply width padding (sometime later)
Example 2:
a = or_bits(#0F0F0000, #12345678)
-- a is #1F3F5678
Example 3:
s = sq_or_bits(#FF, {#123456, #876543, #2211})
-- s is {#1234FF, #8765FF, #22FF}
Implementation: pilx86.e emits inline binary directly for two initialised integers, otherwise a call to :%opOrBits in builtins\VM\pMath.e
or_bitsu() is currently implemented in builtins/ubits.e (also an autoinclude), though that could probably be improved on, if needed.
See Also: and_bits, xor_bits, not_bits, int_to_bits