Difference between revisions of "Shr"
From Lazarus wiki
Jump to navigationJump to searchm |
m (Fixed syntax highlighting; deleted category included in page template) |
||
Line 1: | Line 1: | ||
+ | {{Shr}} | ||
+ | |||
+ | |||
+ | Back to [[Reserved words]]. | ||
− | |||
== Overview == | == Overview == | ||
− | + | ||
− | + | The reserved word '''Sh'''ift '''r'''ight (shr) performs a logical right bit-shift operation (opposite than [[Shl|shl]]). | |
− | '''Sh'''ift '''r'''ight (shr) performs a logical right bit-shift operation (opposite than [[Shl|shl]]). | ||
== Shr with signed types == | == 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. | 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. | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
program ShrTest; | program ShrTest; | ||
begin | begin | ||
Line 19: | Line 21: | ||
== Is a bit set == | == Is a bit set == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
function isBitSet(AValue, ABitNumber:integer):boolean; | function isBitSet(AValue, ABitNumber:integer):boolean; | ||
begin | begin | ||
Line 35: | Line 37: | ||
* [[Or]] | * [[Or]] | ||
* [[Shl]] | * [[Shl]] | ||
− | + | * [[$Bitpacking]] | |
− | [[ | + | * [[Bit manipulation]] |
Revision as of 11:56, 26 February 2020
│
Deutsch (de) │
English (en) │
français (fr) │
русский (ru) │
Back to Reserved words.
Overview
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;
begin
WriteLn(ShortInt(-3) shr 1);
end.
Is a bit set
function isBitSet(AValue, ABitNumber:integer):boolean;
begin
result:=odd(AValue shr ABitNumber);
end;