Difference between revisions of "Xor/fi"
From Lazarus wiki
Jump to navigationJump to searchm (Text replace - "delphi>" to "syntaxhighlight>") |
m (Fixed syntax highlighting; deleted category included in page template) |
||
Line 1: | Line 1: | ||
− | {{Xor}} | + | {{Xor}} |
= Xor boolean lausekkeessa = | = Xor boolean lausekkeessa = | ||
Exclusive or ('''xor''') eli eri- operaation tuloksena on [[True|true]] jos ainostaan toinen operandeista on true (tosi). | Exclusive or ('''xor''') eli eri- operaation tuloksena on [[True|true]] jos ainostaan toinen operandeista on true (tosi). | ||
− | |||
== Totuustaulukko == | == Totuustaulukko == | ||
Line 32: | Line 31: | ||
== Vaihda bitin arvo == | == Vaihda bitin arvo == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
function ToggleBit(const AValue,ABitNumber:integer):integer; | function ToggleBit(const AValue,ABitNumber:integer):integer; | ||
begin | begin | ||
Line 42: | Line 41: | ||
=== Lisätietoja === | === Lisätietoja === | ||
+ | |||
* [[Variable_parameter#XOR swap| XOR swap]] | * [[Variable_parameter#XOR swap| XOR swap]] | ||
* [[Shl]] | * [[Shl]] |
Latest revision as of 08:18, 3 March 2020
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
Xor boolean lausekkeessa
Exclusive or (xor) eli eri- operaation tuloksena on true jos ainostaan toinen operandeista on true (tosi).
Totuustaulukko
A | B | A xor B |
---|---|---|
false | false | false |
false | true | true |
true | false | true |
true | true | false |
Xor bittikohtaisissa toiminnoissa
Bitettäin tehtävä xor asettaa kyseisen bitin ykköseksi (1) jos vastaavat bitit eivät ole samoja ja nollaksi (0) jos ne ovat samoja.
Vaihda bitin arvo
function ToggleBit(const AValue,ABitNumber:integer):integer;
begin
result := AValue xor 1 shl ABitNumber;
end;
Jos kutsut funktiota ToggleBit(11,0) niin funktio palauttaa arvon 10. Jos kutsu on ToggleBit(10,2) niin palautettava arvo on 14.