DelphiBasics
 XorKeyword Boolean Xor or bitwise Xor of two arguments
 1 Boolean expression Xor Boolean expression 2 Integer expression Xor Integer expression
Description
The Xor keyword is used in two different ways:

1. To perform a logical or boolean 'Exclusive-or' of two logical values. If they are different, then the result is true.

2. To perform a mathematical 'Exclusive-or' of two integers. The result is a bitwise 'Exclusive-or' of the two numbers. For example:

10110001 Xor 01100110 = 11010111
Notes
If the boolean expression is calculated (as opposed to being a Boolean variable), then brackets are required to isolate it.
Related commands
 And Boolean and or bitwise and of two arguments Not Boolean Not or bitwise not of one arguments Or Boolean or or bitwise or of two arguments
Author links

Buy Website Traffic at
Buywebsitetrafficexperts.com

Buy Proxies at
Buyproxies.io

Download this web site as a Windows program.

 Example code : Illustrate both types of Xor usage var   num1, num2, num3 : Integer;   letter           : Char; begin  num1   := \$25;    // Binary value : 0010 0101   \$25  num2   := \$32;    // Binary value : 0011 0010   \$32                    // XOr'ed value : 0001 0111 = \$17   letter := 'G';   // And used to return a Boolean value   if (num1 > 0) Xor (letter = 'G')   then ShowMessage('Only one of the values is true')   else ShowMessage('Both values are true or false');   // And used to perform a mathematical Xor operation   num3 := num1 Xor num2;   // Display the result   ShowMessageFmt('\$25 Xor \$32 = \$%x',[num3]); end; Show full unit code Both values are true or false   \$25 Xor \$32 = \$17
 Delphi Programming © Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page