Difference between revisions of "Shl"
From Free Pascal wiki
Jump to navigationJump to searchm (Text replace - "delphi>" to "syntaxhighlight>") |
|||
Line 10: | Line 10: | ||
== Clear a bit == | == Clear a bit == | ||
− | < | + | <syntaxhighlight> |
function ClearBit( const aValue, aBitNumber : integer ) : integer; | function ClearBit( const aValue, aBitNumber : integer ) : integer; | ||
begin | begin | ||
result := aValue and not( 1 shl aBitNumber ); | result := aValue and not( 1 shl aBitNumber ); | ||
end; | end; | ||
− | </ | + | </syntaxhighlight> |
If you call ClearBit(%1111,1) then get %1101 (%1111 = 15 and %1101 = 13). If you call ClearBit(13,2) then get 9 (9 = %1001) . | If you call ClearBit(%1111,1) then get %1101 (%1111 = 15 and %1101 = 13). If you call ClearBit(13,2) then get 9 (9 = %1001) . |
Revision as of 14:49, 24 March 2012
Shift left (shl) performs a left bit-shift operation (opposite than shr).
E.g
Command is: 00000100 shl 2 Action is: 00000100 <- 00 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 get %1101 (%1111 = 15 and %1101 = 13). If you call ClearBit(13,2) then get 9 (9 = %1001) .