[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.308 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 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

section 9.7 and, section 9.180 or, section 8.3 Operators.



This document was generated by Frank Heckenbach on May, 10 2002 using texi2html