Difference between revisions of "Shr"
From Lazarus wiki
Jump to navigationJump to search (→Overview: Added an example showing how "shr" works. Copied from https://wiki.freepascal.org/Shl and modified.) |
(→Shr with signed types: Added the internal link to "Typecast".) |
||
Line 18: | Line 18: | ||
== 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|typecast]] and extension to a larger unsigned type may be performed before the shift operation. Check what the following program actually prints. |
<syntaxhighlight lang=pascal> | <syntaxhighlight lang=pascal> |
Revision as of 04:59, 1 September 2021
│
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).
Example:
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.
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;
operators |
|
---|---|
see also |
|