Xor/de
Deutsch · English · Français · Suomi · Русский
XOR
Boolescher XOR-Operator
Ein boolescher XOR-Operator (von engl. eXclusive OR, exklusives Oder) ist ein Operator in Pascal. Das Ergebnis ist TRUE, wenn ein Operand TRUE ist und der andere FALSE.
Beispiele
| A | B | A XOR B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE | FALSE |
Bitweiser XOR-Operator
Ein bitweises XOR (von engl. eXclusive OR, exklusives Oder) wird auf zwei gleich lange Operanden angewendet. Das Ergebnis ist 0 wenn die Bits gleich sind, sonst ist es 1.
Beispiele
| A | 0101 | 0101 |
|---|---|---|
| B | 0110 | 0011 |
| A XOR B | 0011 | 0110 |
Unterschied zum OR-Operator
Das Ergebnis von OR ist TRUE, wenn mindestens ein Operand TRUE ist. Das Ergebnis von XOR ist TRUE, wenn genau ein Operand TRUE ist.
Verschlüsseln mit XOR
Mit xor kann man Daten verschlüsseln, dazu ein kleines Beispiel, mit einem String.
const
hello = 'Hello World !';
Key = %11001010; // Schlüsselbyte
var
i: integer;
sVerschluesselt,
sEntschluesselt: ShortString;
begin
// String verschlüsseln
for i := 0 to Length(hello) do begin
sVerschluesselt[i] := Char(Byte(hello[i]) xor Key);
end;
// String entschlüsseln
for i := 0 to Length(hello) do begin
sEntschluesselt[i] := Char(Byte(sVerschluesselt[i]) xor Key);
end;
// Zur Überprüfung ausgeben
WriteLn(sVerschluesselt); // Undefinierte Zeichen
WriteLn(sEntschluesselt); // Wieder "Hello World !"
end.--ReneHSZ (talk) 14:34, 12 July 2016 (CEST)
From the Free Pascal wiki, page "Xor/de", as it stood on 2018-01-14 after a change by Mathias, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 3 people, 2012–2018
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Olaf | Created page | |
| Olaf | (minor) | |
| Olaf | (minor) | |
| Olaf | (minor) | |
| Olaf | (minor) | |
| Olaf | (minor) | |
| ReneHSZ | XOR wurde beschrieben und Beispiele hinzugefügt | |
| Mathias | Unterschied zum OR-Operator | |
| Mathias | Verschlüsseln mit XOR | |
| Mathias |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
