Name
Xor Keyword
Syntax
Boolean expressionxorBoolean expressionInteger expressionxorInteger expression
Description
The xor operator performs
an exclusive or on its operands. If the operands
are of Boolean type, it returns a Boolean result: True if the
operands are different and False if they are the same.
An integer xor operates on each bit of its
operands, setting the result bit to 1 if the corresponding bits in
both operands are different, and to
if both operands have identical bits. If one operand is smaller than
the other, Delphi extends the smaller operand with
in the leftmost bits. The result is the size of the largest operand.
Tips and Tricks
With Boolean operands,
xoris just like comparing for inequality. In most cases, the<>operator is easier to understand than usingxor.The
xoroperation is reversible, which leads some people to use it for encrypting passwords. Usingxorto encrypt passwords is like using bubble gum to lock a door. It doesn’t work, and it’s easy to break in. Search the World Wide Web to find free, reusable solutions for securely encrypting passwords.
Examples
var
I, J: Integer;
begin
I := $25;
J := $11;
WriteLn(I xor J); // Writes 52 (which is $34)
...See Also
| And Keyword, Boolean Type, ByteBool Type, LongBool Type, Not Keyword, Or Keyword, Shl Keyword, Shr Keyword, WordBool Type, Xor Keyword, $B Compiler Directive, $BoolEval Compiler Directive |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access