Difference between revisions of "Shr"

From Lazarus wiki
Jump to navigationJump to search
m
Line 1: Line 1:
 +
{{shr}}
 +
 
== Overview ==
 
== Overview ==
{{shr}}
 
 
<br>
 
<br>
 
<br>
 
<br>

Revision as of 03:09, 22 July 2015

Deutsch (de) English (en) français (fr) русский (ru)


Overview



Shift right (shr) performs a logical right bit-shift operation (opposite than shl).

Shr with signed types

Note: unlike the >> operator in the C language, the shr operator is a logical (not arithmetic) bit shift, even if the left operand is a signed integer. An implicit typecast and extension to a larger unsigned type may be performed before the shift operation. Check what the following program actually prints.

program ShrTest;
begin
  WriteLn(ShortInt(-3) shr 1);
end.

Is a bit set

function isBitSet(AValue, ABitNumber:integer):boolean;
begin
   result:=odd(AValue shr ABitNumber);
end;

See also