Shr/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Shr/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Généralités | |
| 2 | + | ||
| 3 | + | **Shr** (Shift right) décale à droite une valeur binaire spécifié en premier opérande du nombre de bit spécifié en second opérande (contraire de [[Shl/fr|shl]]). | |
| 4 | + | ||
| 5 | + | ## Shr avec les types signés | |
| 6 | + | ||
| 7 | + | Note: contrairement à l'opérateur \>\> en langage C, l'opérateur shr est un décalage de bit logique (non arithmétique), même si l'opérande de gauche est un entier signé. Une conversion de type implicite et un extension vers un type non signé plus large peut être réalisée avant l'opération de décalage. Vérifiez ce que le programme suivant imprime réellement. | |
| 8 | + | ||
| 9 | + | ``` pascal | |
| 10 | + | program ShrTest; | |
| 11 | + | begin | |
| 12 | + | WriteLn(ShortInt(-3) shr 1); | |
| 13 | + | end. | |
| 14 | + | ``` | |
| 15 | + | ||
| 16 | + | ## Le bit est-il mis ? | |
| 17 | + | ||
| 18 | + | ``` pascal | |
| 19 | + | function isBitSet(AValue, ABitNumber:integer):boolean; | |
| 20 | + | begin | |
| 21 | + | result:=odd(AValue shr ABitNumber); | |
| 22 | + | end; | |
| 23 | + | ``` | |
| 24 | + | ||
| 25 | + | ## Voir aussi | |
| 26 | + | ||
| 27 | + | - [[And/fr|And]] | |
| 28 | + | - [[Boolean/fr|Booléen]] | |
| 29 | + | - [[Const/fr|Const]] | |
| 30 | + | - [[Function/fr|Fonction]] | |
| 31 | + | - [[Integer/fr|Type Integer]] | |
| 32 | + | - [[Odd/fr|Odd]] | |
| 33 | + | - [[Or/fr|Or]] | |
| 34 | + | - [[Shl/fr|Shl]] | |
| 35 | + | ||
| 36 | + | --- | |
| 37 | + | *From the Free Pascal wiki, page "Shr/fr", as it stood on 2020-02-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).* |
