Difference between revisions of "Shl"
From Lazarus wiki
Jump to navigationJump to searchm |
m (Fixed syntax highlighting; deleted category included in page template) |
||
Line 1: | Line 1: | ||
+ | {{Shl}} | ||
− | |||
− | |||
− | |||
== Overview == | == Overview == | ||
+ | |||
'''Sh'''ift '''l'''eft ('''shl''') performs a left bit-shift operation, shifting the value byt the amount of bits specified as an argument (opposite of [[Shr|shr]]). | '''Sh'''ift '''l'''eft ('''shl''') performs a left bit-shift operation, shifting the value byt the amount of bits specified as an argument (opposite of [[Shr|shr]]). | ||
Line 15: | Line 14: | ||
== Clear a bit == | == Clear a bit == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
function ClearBit( const aValue, aBitNumber : integer ) : integer; | function ClearBit( const aValue, aBitNumber : integer ) : integer; | ||
begin | begin | ||
Line 33: | Line 32: | ||
* [[Shr]] | * [[Shr]] | ||
* [[Bit manipulation]] | * [[Bit manipulation]] | ||
− | + | * [[$Bitpacking]] | |
− | [[ |
Revision as of 12:46, 26 February 2020
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
Overview
Shift left (shl) performs a left bit-shift operation, shifting the value byt the amount of bits specified as an argument (opposite of shr).
E.g
Command is: 00000100 shl 2 (shift left 2 bits) Action is: 00000100 <- 00 (00 gets added to the right of the value; left 00 "disappears") Result is: 00010000
Clear a bit
function ClearBit( const aValue, aBitNumber : integer ) : integer;
begin
result := aValue and not( 1 shl aBitNumber );
end;
If you call ClearBit(%1111,1), then you get %1101 (The binary number %1111 is 15 and %1101 = 13).
If you call ClearBit(13,2), then you get 9 (9 = %1001) .