[fpc-pascal] shift right operation with variables

Xiangrong Fang xrfang at gmail.com
Mon Aug 17 03:38:13 CEST 2015


Hi All,

I noticed a strange behavior with the following program:

program tt;
{$mode objfpc}{$H+}
uses sysutils;
var
  res: Integer;
  mask1, mask2: QWord;
begin
  mask1 := $FFFFFFFFFFFFFFFF shr 24;
  WriteLn(IntToHex(mask1, 16));
  res := 24;
  mask2 := $FFFFFFFFFFFFFFFF shr res;
  WriteLn(IntToHex(mask2, 16));
end.

The output is:

000000FFFFFFFFFF
00000000000000FF

Why they are different? How can I ensure the result is like SHR with
constant.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150817/66b81464/attachment.html>


More information about the fpc-pascal mailing list