Shl/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Shl/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Généralité | |
| 2 | + | ||
| 3 | + | **Shl** (Shift Left) décale à gauche une valeur binaire spécifié en premier opérande du nombre de bit spécifié en second opérande (contraire de [[Shr/fr|shr]]). | |
| 4 | + | ||
| 5 | + | P.ex. | |
| 6 | + | ||
| 7 | + | `L'instruction est : 00000100 shl 2 (décalage à gauche de 2 bits)`\ | |
| 8 | + | ` `\ | |
| 9 | + | `L'action est : 00000100 <- 00 (00 ajoute 2 00 à droite, les 00 de gauche "disparaissent")`\ | |
| 10 | + | ` `\ | |
| 11 | + | `Le résultat est : 00010000` | |
| 12 | + | ||
| 13 | + | Autrement dit, cela revient à multiplier par la puissance de 2 équivalente (2^décalage = 4, dans notre exemple). | |
| 14 | + | ||
| 15 | + | ## Effacer un bit | |
| 16 | + | ||
| 17 | + | ``` pascal | |
| 18 | + | function ClearBit( const aValue, aBitNumber : integer ) : integer; | |
| 19 | + | begin | |
| 20 | + | result := aValue and not( 1 shl aBitNumber ); | |
| 21 | + | end; | |
| 22 | + | ``` | |
| 23 | + | ||
| 24 | + | Si vous appelez ClearBit(%1111,1), vous obtenez %1101 (soit le [[Binary numeral system/fr|nombre binaire]] 13). | |
| 25 | + | ||
| 26 | + | Si vous appelez ClearBit(13,2), vous obtenez 9 (9 = %1001). | |
| 27 | + | ||
| 28 | + | If you call ClearBit(13,2), then you get 9 (9 = %1001) . | |
| 29 | + | ||
| 30 | + | ## See also | |
| 31 | + | ||
| 32 | + | - [[And/fr|And]] | |
| 33 | + | - [[Not/fr|Not]] | |
| 34 | + | - [[Or/fr|Set a bit]] | |
| 35 | + | - [[Xor/fr|Toggle a bit]] | |
| 36 | + | - [[Shr/fr|Shr]] | |
| 37 | + | - [[Bit manipulation/fr|Manipulation de bits]] | |
| 38 | + | ||
| 39 | + | --- | |
| 40 | + | *From the Free Pascal wiki, page "Shl/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).* |
