And/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: And/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Opération booléenne | |
| 2 | + | ||
| 3 | + | **And** produit une valeur [[True/fr|true]] si et seulement si ses deux opérandes sont True ensemble. | |
| 4 | + | ||
| 5 | + | ### Table de vérité | |
| 6 | + | ||
| 7 | + | | A | B | A and B | | |
| 8 | + | |-----------|-----------|---------| | |
| 9 | + | | false | false | false | | |
| 10 | + | | false | true | false | | |
| 11 | + | | true | false | false | | |
| 12 | + | | true | true | true | | |
| 13 | + | ||
| 14 | + | ## Opération bit à bit | |
| 15 | + | ||
| 16 | + | And bit à bit met à 1 un bit si les bits correspondant des opérandes sont égaux à 1. | |
| 17 | + | ||
| 18 | + | ### Est une puissance de 2 | |
| 19 | + | ||
| 20 | + | ``` pascal | |
| 21 | + | function IsPowerOfTwo( const aValue : longint ): boolean; | |
| 22 | + | var | |
| 23 | + | x : longint; | |
| 24 | + | b : boolean; | |
| 25 | + | begin | |
| 26 | + | b := false; | |
| 27 | + | if aValue <> 0 then | |
| 28 | + | begin | |
| 29 | + | x := aValue - 1; | |
| 30 | + | x := x and aValue; | |
| 31 | + | if x = 0 then b := true; | |
| 32 | + | end; | |
| 33 | + | result := b; | |
| 34 | + | end; | |
| 35 | + | ``` | |
| 36 | + | ||
| 37 | + | Si vous appelez IsPowerOfTwo(4) alors vous obtenez True. SI vous appelez IsPowerOfTwo(5) alors vous obtenez False . | |
| 38 | + | ||
| 39 | + | ## Voir aussi | |
| 40 | + | ||
| 41 | + | - [[Not/fr|Not]] | |
| 42 | + | - [[Or/fr|Or]] | |
| 43 | + | - [[Shl/fr|Shl]] | |
| 44 | + | - [[Bit manipulation/fr|Manipulation de bit]] | |
| 45 | + | ||
| 46 | + | --- | |
| 47 | + | *From the Free Pascal wiki, page "And/fr", 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).* |
