Difference between revisions of "Shl"

From Lazarus wiki
Jump to navigationJump to search
Line 30: Line 30:
 
* [[Or# Set a bit|Set a bit]]
 
* [[Or# Set a bit|Set a bit]]
 
* [[Xor# Toggle a bit|Toggle a bit]]
 
* [[Xor# Toggle a bit|Toggle a bit]]
* [[Shl]]
+
* [[Shr]]
 
* [[Bit manipulation]]
 
* [[Bit manipulation]]
  
 
[[Category:Pascal]]
 
[[Category:Pascal]]

Revision as of 09:01, 28 October 2014

Template:shl

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 (%1111 = 15 and %1101 = 13).

If you call ClearBit(13,2), then you get 9 (9 = %1001) .

See also