BitXor


The BitXor function returns the bit-wise XOR of two numbers. The name XOR means "Exclusive OR" and refers to the case where 1 but not both numbers have a given bit "on". Use the bit-wise XOR to combine bits from separate numbers when each bit is present in one number but not the other.

Syntax

nResult = BitXor( n1, n2 )

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

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

Remarks

The bit-wise XOR of two numbers saves all bits found exclusively in both numbers. Exclusive means that the bit was "on" in one number but not in both numbers. For example, consider the numbers 7 and 18. In binary notation these are expressed as 111 and 10010. The bit-wise XOR of 7 and 18 selects only the bits present in one but not both numbers, which gives 10101, or 21 decimal.

Example

The following script performs the XOR 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'", BitXor( n1, n2 ) )

-- prints the result 21

Related Topics

Boolean Math Functions

BitOr


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