And/fi: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - | ||
| 9 | 1 | # And (ja) boolean lausekkeessa | |
| 10 | 2 | ||
| 11 | - | ||
| 3 | + | **And** eli **ja** -operaatio antaa [[True|true]] eli tosi arvon vain silloin kun molemmat operandit ovat tosia (true). Muissa tapauksissa tuloksena on epätosi eli [[False|false]]. | |
| 12 | 4 | ||
| 13 | 5 | ## And eli ja-operaation totuustaulukko | |
| 14 | 6 | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 7 | + | | A | B | A and B (eli A ja B) | | |
| 8 | + | |:---------:|:---------:|--------------------------| | |
| 9 | + | | false | false | false | | |
| 10 | + | | false | true | false | | |
| 11 | + | | true | false | false | | |
| 12 | + | | true | true | true | | |
| 13 | + | ||
| 22 | 14 | # And eli ja bittikohtaisissa toiminnoissa | |
| 23 | 15 | ||
| 24 | - | ||
| 16 | + | Bitettäin tehtävä and (ja) asettaa kyseisen bitin ykköseksi (1) jos molemmat vastaavat bitit ovat ykkösiä (1). Muussa tapauksessa tulos on nolla (0). | |
| 25 | 17 | ||
| 26 | 18 | ## Onko kakkosen potenssi | |
| 27 | - | ||
| 19 | + | ||
| 20 | + | ``` pascal | |
| 28 | 21 | function IsPowerOfTwo( const aValue : longint ): boolean; | |
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 22 | + | var | |
| 23 | + | x : longint; | |
| 24 | + | b : boolean; | |
| 25 | + | begin | |
| 26 | + | b := false; | |
| 27 | + | if aValue <> 0 then | |
| 32 | 28 | begin | |
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 29 | + | x := aValue - 1; | |
| 30 | + | x := x and aValue; | |
| 31 | + | if x = 0 then b := true; | |
| 41 | 32 | end; | |
| 33 | + | result := b; | |
| 34 | + | end; | |
| 42 | 35 | ``` | |
| 43 | 36 | ||
| 44 | - | ||
| 37 | + | Jos kutsutaan IsPowerOfTwo(4) niin saadaan true. Jos kutsutaan IsPowerOfTwo(5) niin saadaan false . | |
| 45 | 38 | ||
| 46 | 39 | ### Lisätietoa | |
| 47 | 40 | ||
| 48 | - | ||
| 49 | - | ||
| 41 | + | - [[Not]] | |
| 42 | + | - [[Shl]] | |
| 50 | 43 | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 44 | + | - [[Const/fi|Const]] | |
| 45 | + | - [[Function]] | |
| 46 | + | - [[Integer/fi|Integer]] | |
| 54 | 47 | ||
| 55 | - | ||
| 48 | + | - [[Shl|Clear a bit]] | |
| 56 | 49 | ||
| 57 | 50 | --- | |
| 58 | - | ||
| 51 | + | *From the Free Pascal wiki, page "And/fi", as it stood on 2020-01-26 after a change by Trev, 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).* | |
| 52 | + | Category: Suomi |
