BitOr
The BitOr function returns the bit-wise OR of two numbers. Use the bit-wise OR to combine bits from separate numbers, such as when making a bit mask.
nResult = BitOr( n1, n2 ) |
The bit-wise OR of two numbers saves all bits found in both numbers. For example, consider the numbers 4 and 16. In binary notation these are expressed as 100 and 10000. The bit-wise OR preserves all "on" bits from both numbers, giving 10100, or 20 decimal. Similarly, (7 OR 18) in binary representation is (111 OR 10010), which equals 10111 binary, or 23 decimal.
The OR operation is often used in conjunction with the AND operation (see BitAnd) to pack binary flag bits (i.e., 1, 2, 4, 8, 16, ... ) that will then be unpacked using the AND operation against the flags bit values or by testing specific bits using the BitTest function.
The following script performs the OR of two numbers. Note that the result is printed using %u because it is considered an unsigned (i.e., 0 or positive) integer.
|
-- pick two numbers |
|
-- prints the result 23 |