Function BXOr() Foundation

Calculates the result of a bitwise XOR operation.

BXOr( <nVa1>, <nVal2>, [<nVal3>,...] ) -> nBitwiseXOr
<nVal1> is a numeric expression that is used as the first operand for the bitwise XOR operation.
<nVal2> is a numeric expression that is used as the second operand. The parameter may be followed by an arbitrary number of additional operands.

BXOr() returns the result of a bitwise exclusive-OR operation between operands <nVal1> and <nVal2>. If additional parameters are passed, another bitwise XOR operation is performed for each parameter. Once all parameters are processed, BXOr() returns the combined result of the XOR operation.


BXOr() is a numeric function that performs a bitwise exclusive-OR operation between two or more operands. A bitwise XOR turns on all bits in the result that have a corresponding bit set in one but not in both operands. The following table illustrates this correlation.

Results produced by a bitwise XOR operation
Operand 1 Operand 2 Result
0 0 0
1 0 1
0 1 1
1 1 0

Bitwise operations are usually used with flag values, where a certain bit pattern represents a certain option being enabled or disabled. Using the function BXOr(), an individual option can easily be removed (disabled) from the flag value.

// The example illustrates an exemplary usage of function BXOr() 

#define OPTION_1     1 
#define OPTION_2     2 
#define OPTION_3     4 

#define DEFAULTS     OPTION_1 + OPTION_2 + OPTION_3 


 LOCAL nSetting := DEFAULTS 

   nSetting := RemOption( nSetting, OPTION_2 ) 
   ? nSetting             // Result: 5 (OPTION_1 + OPTION_3) 
   nSetting := RemOption( nSetting, OPTION_3 ) 
   ? nSetting             // Result: 1 (OPTION_1) 

   WAIT "Done." 


// Remove option 'nOption' from the 
// value passed 
FUNCTION RemOption( nValue, nOption ) 
RETURN BXOr(nValue, nOption) 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.