Difference between revisions of "Shr"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; deleted category included in page template)
(add footer)
Line 28: Line 28:
== See also ==
{{Logical operators}}
* [[And]]
* [[Boolean]]
* [[Const]]
* [[Const]]
* [[Function]]
* [[Function]]
* [[Integer]]
* [[Integer]]
* [[Odd]]
* [[Or]]
* [[Shl]]
* [[$Bitpacking]]
* [[Bit manipulation]]

Revision as of 22:38, 16 October 2020

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

Back to Reserved words.


The reserved word 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;
  WriteLn(ShortInt(-3) shr 1);

Is a bit set

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

navigation bar: Pascal logical operators

and • or • not • xor
shl • shr
and_then (N/A)• or_else (N/A)

see also

{$boolEval} • Reference: § “boolean operators” • Reference: § “logical operators”