BitAnd BitXor

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.

Syntax

nResult = BitOr( n1, n2 )

bullet.gif    nResult is the bit-wise OR of n1 and n2.

bullet.gif    n1 and n2 are two numbers (integers).

Remarks

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.

Example

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.

n1 = 7 n2 = 18

-- pick two numbers

Printf( "'%u'", BitOr( n1, n2 ) )

-- prints the result 23

Related Topics

Boolean Math Functions

BitAnd

BitXor

BitNor


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.