Node:xor, Previous:WriteStr, Up:Reference



xor

Synopsis


operator xor (operand1, operand2: Boolean) = Result: Boolean;
or
operator xor (operand1, operand2: integer_type) = Result: integer_type;
or
procedure xor (var operand1: integer_type; operand2: integer_type);

Description

In GNU Pascal, xor has three built-in meanings:

  1. Logical "exclusive or" between two Boolean-type expressions. The result of the operation is of Boolean type. (Logical foo xor bar in fact has the same effect as foo <> bar.)
  2. Bitwise "exclusive or" between two integer-type expressions. The result is of the common integer type of both expressions.
  3. Use as a "procedure": operand1 is "xor"ed bitwise with operand2; the result is stored in operand1.

Conforming to

ISO Pascal does not define the xor operator; Borland Pascal and Delphi do.

Use of xor as a "procedure" is a GNU Pascal extension.

Example


program XorDemo;
var
  a, b, c: Integer;
begin
  if (a = 0) xor (b = 0) then
    c := 1  { happens if either `a' or `b' is zero,    }
            { but not if both are zero or both nonzero }
  else if (a xor b) = 0 then  { bitwise xor }
    c := 2  { happens if a = b }
  else
    xor (c, a)  { same as `c := c xor a' }
end.

See also

Keywords, and, or, Operators.