Sign in Join
Wiki copytemporary

Xor/de: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Xor/de

OldNewLine
1+# XOR
2+
3+## Boolescher XOR-Operator
4+
5+Ein boolescher **XOR**-Operator (von engl. e**X**clusive **OR**, exklusives Oder) ist ein Operator in Pascal. Das Ergebnis ist TRUE, wenn ein Operand TRUE ist und der andere FALSE.
6+
7+### Beispiele
8+
9+| A | B | **A XOR B** |
10+|-------|-------|-------------|
11+| FALSE | FALSE | FALSE |
12+| FALSE | TRUE | TRUE |
13+| TRUE | FALSE | TRUE |
14+| TRUE | TRUE | FALSE |
15+
16+## Bitweiser XOR-Operator
17+
18+Ein bitweises XOR (von engl. e**X**clusive **OR**, exklusives Oder) wird auf zwei gleich lange Operanden angewendet. Das Ergebnis ist 0 wenn die Bits gleich sind, sonst ist es 1.
19+
20+### Beispiele
21+
22+| A | 0101 | 0101 |
23+|---------|------|------|
24+| B | 0110 | 0011 |
25+| A XOR B | 0011 | 0110 |
26+
27+## Unterschied zum OR-Operator
28+
29+Das Ergebnis von OR ist TRUE, wenn mindestens ein Operand TRUE ist. Das Ergebnis von XOR ist TRUE, wenn genau ein Operand TRUE ist.
30+
31+## Verschlüsseln mit **XOR**
32+
33+Mit **xor** kann man Daten verschlüsseln, dazu ein kleines Beispiel, mit einem String.
34+
35+``` pascal
36+const
37+ hello = 'Hello World !';
38+ Key = %11001010; // Schlüsselbyte
39+
40+var
41+ i: integer;
42+ sVerschluesselt,
43+ sEntschluesselt: ShortString;
44+
45+begin
46+ // String verschlüsseln
47+ for i := 0 to Length(hello) do begin
48+ sVerschluesselt[i] := Char(Byte(hello[i]) xor Key);
49+ end;
50+
51+ // String entschlüsseln
52+ for i := 0 to Length(hello) do begin
53+ sEntschluesselt[i] := Char(Byte(sVerschluesselt[i]) xor Key);
54+ end;
55+
56+ // Zur Überprüfung ausgeben
57+ WriteLn(sVerschluesselt); // Undefinierte Zeichen
58+ WriteLn(sEntschluesselt); // Wieder "Hello World !"
59+end.
60+```
61+
62+--ReneHSZ ([[User talk:ReneHSZ|talk]]) 14:34, 12 July 2016 (CEST)
63+
64+---
65+*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](/wiki-contact).*
66+Category: Deutsch
67+Category: Pascal/de
68+Category: Reserved words/de

Back to history