Sign in Join
Wiki copytemporary

Shl: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Back to [[Reserved words]].
22
33## Overview
44
55The reserved word **Sh**ift **l**eft (**shl**) performs a left bit-shift operation, shifting the value by the amount of bits specified as an argument (opposite of [[Shr|shr]]).
66
77Example:
88
9-`Command is: 00000100 shl 2 (shift left 2 bits)`\
10-` `\
11-`Action is:  00000100 <- 00 (00 gets added to the right of the value; left 00 "disappears")`\
12-` `\
13-`Result is:  00010000`
9+```text
10+Command is: 00000100 shl 2 (shift left 2 bits)
11+
12+Action is: 00000100 <- 00 (00 gets added to the right of the value; left 00 "disappears")
13+
14+Result is: 00010000
15+```
1416
1517## Clear a bit
1618
1719``` pascal
1820function ClearBit( const aValue, aBitNumber : integer ) : integer;
1921begin
2022// sanity check supplied value
2123 if (aBitNumber <0) or (aBitNumber >15) then
2224 result :=0
2325 else
2426// value ok
2527 result := aValue and not( 1 shl aBitNumber );
2628end;
2729```
2830
2931If you call ClearBit(%1111,1), then you get %1101 (The [[Binary numeral system|binary number]] %1111 is 15 and %1101 = 13).
3032
3133If you call ClearBit(13,2), then you get 9 (9 = %1001).
3234
3335In this case, bits are numbered right to left from 0 to 15, bit 0 being the ones bit and bit 15 being the sign bit.
3436
3537- [[Or|Set a bit]]
3638- [[Xor|Toggle a bit]]
3739- [[Bit manipulation]]
3840- [[$Bitpacking]]
3941
4042---
4143*From the Free Pascal wiki, page "Shl", as it stood on 2021-08-29 after a change by AndreasFilsinger, 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).*
4244Category: Code
4345Category: Operators

Back to history