Sign in Join
Wiki copytemporary

Shr

Deutsch · English · Français · Русский

Back to Reserved words.

Overview

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

Example:

text
Command is: 00000100 shr 2 (shift right 2 bits)
 
Action is:  00000100 -> 00 (00 gets added to the left of the value; right 00 "disappears")
 
Result is:  00000001

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.

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

Is a bit set

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

From the Free Pascal wiki, page "Shr", as it stood on 2021-09-01 after a change by Mozi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.