XOR

Top  Previous  Next

The logical operator XOR operates on expressions with the BOOL, SINT, INT and DINT data types. When operating on data types other than BOOL, the operation is bitwise.

When operating on BOOL, it has the following truth table:

 

 

  Input 1     Input 2       Output1

-----------------------------------------

     0               0                0

     0               1                1

     1               0                1

     1               1                0

-----------------------------------------

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  a : BOOL;
  b : BOOL;
  ia : INT;
  ib : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  ...
  // All bits in ib that are different than 16#00FF will be set in ia (see thruth table)
  ia := ib XOR 16#00FF;
  ...
  IF a XOR b THEN
    // This will be executed if a and b are different
     ...
  END_IF;
  ...
END;
 
END_PROGRAM;