Difference between revisions of "Xor"
From Free Pascal wiki
Jump to navigationJump to search (add footer, cat) |
(→Bitwise operation: Added an example showing how "xor" works.) |
||
Line 30: | Line 30: | ||
Bitwise xor sets the bit to 1 where the corresponding bits in its operands are different, and to 0 if they are the same. | Bitwise xor sets the bit to 1 where the corresponding bits in its operands are different, and to 0 if they are the same. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | 0101'1010 | ||
+ | xor 0011'0100 | ||
+ | ――――――――――――― | ||
+ | 0110'1110 | ||
== Toggle a bit == | == Toggle a bit == |
Revision as of 05:17, 1 September 2021
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
Back to Reserved words.
The xor operator
compares two boolean
values, and returns true if and only if one of them is true.
Boolean operation
Exclusive or (xor) results in a value of true if and only if exactly one of the operands has a value of true.
Truth table
A | B | A xor B |
---|---|---|
false | false | false |
false | true | true |
true | false | true |
true | true | false |
Bitwise operation
Bitwise xor sets the bit to 1 where the corresponding bits in its operands are different, and to 0 if they are the same.
Example:
0101'1010 xor 0011'0100 ――――――――――――― 0110'1110
Toggle a bit
function ToggleBit(const AValue,ABitNumber:integer):integer;
begin
result := AValue xor 1 shl ABitNumber;
end;
If you call ToggleBit(11,0) then get 10. If you call ToggleBit(10,2) then get 14.
operators |
|
---|---|
see also |
|