XOR
 
Syntax

number XOR number
Description

Xor, at its most primitive level, is a boolean operation, a logic function that takes in two bits and outputs a resulting bit. If given two bits, this function returns true if ONLY one of the bits are true, and false for any other combination. The truth table below demonstrates all combinations of a boolean xor operation:
Bit1     Bit2    Result
 0         0        0
 1         0        1
 0         1        1
 1         1        0

This holds true for conditional expressions in ARMbasic. When using "Xor" encased in an If block, While loop, or Do loop, the output will behave quite literally:
IF condition1 XOR condition2 THEN expression1

Is translated as:
IF condition1 IS only true, OR only condition2 IS true, THEN perform expression1

When given two expressions, numbers, or variables that return a number that is more than a single bit, Xor is performed "bitwise". A bitwise operation compares each bit of one number, with each bit of another number, performing a logic operation for every bit.
The boolean math expression below describes this:
00001111 XOR
00011110
--------  equals
00010001

Notice how in the resulting number of the operation, reflects an XOR operation performed on each bit of the top operand, with each corresponding bit of the bottom operand. The same logic is also used when working with conditions.
Example

' Using the XOR operator on two numeric values

numeric_value1 = 15 '00001111
numeric_value2 = 30 '00011110

'Result =  17  =     00010001
PRINT numeric_value1 AND numeric_value2
END

' Using the XOR operator on two conditional expressions

numeric_value1 = 10
numeric_value2 = 15

IF numeric_value1 = 10 XOR numeric_value2 = 20 THEN PRINT "Numeric_Value1 equals 10 or Numeric_Value2 equals 20"
END

' This will output "Numeric_Value1 equals 10 or Numeric_Value2 equals 20"
' because only the first condition of the IF statement is true
 

Differences from PBASIC

See also