User Tools

Site Tools


xor

Table of Contents

xor

xor is a logical “exclusive or” operator

syntax

result = numeric-expression1 xor numeric-expression2

See also and, nor, not, or, eqv, imp

details

the xor logical operator compares two expressions and returns the boolean value true if one and only one of the expressions is true (non-zero). See the table below for possible results.

expression 1    expression 2    result
    true            true         false
    true            false        true
    false           true         true
    false           false        false

Logical operators are not to be confused with Bitwise Operators.

example

In this example a comparison is performed on two integer variables using an if-statement.

' SharpBASIC xor programming example
' ----------------------------------
incl "lib/sys.sbi";

dim a, b: int;

main do
  a = 1;
  b = 0;
  if a xor b do
    print(true);
  else do
    print(false);
  end
end
Output:

-1

xor.txt · Last modified: 2023/06/26 10:42 by admin