BitwiseXOR

Description

Allows you to compare the bits from two binary numbers, setting all matched bits to 0 and mismatched bits to 1.

Syntax

BitwiseXOR ( val1, val2)

Argument

Description

val1

Unsigned long for the first binary number you want to compare

val2

Unsigned long for the second binary number you want to compare

Returns

UnsignedLong. Returns the result of a bitwise XOR operation. If one of its arguments is null, BitwiseXOR returns null.

Usage

The bitwise “exclusive” OR operator compares each bit of its first operand to the corresponding bit of its second operand. If the bit at a particular position of one operand is 0 and the bit at the same position in the other operand is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Examples

Example 1

This example the values of the bits in the firstValue and secondValue variables:

UnsignedLong ll_result

ll_result = BitwiseXOR(firstValue, secondValue)

In this example, if firstValue is 10, it has bits in the second and fourth positions. If secondValue is 12, it has bits in the third and fourth positions. When you compare the binary values of 10 and 12 in a bitwise exclusive OR operation, the result is 6, with bits set in the second and third positions only.

See also