Re: [fpc-pascal] shift right operation with variables

2015-08-18 Thread Michael Schnell
AFAIK literals are integer unless denoted otherwise The type of the operands determines the operation. this is rather obvious for e.g. + but not obvious for shift operations. AFAIK, the type left of the := does not determine the operation. This is not obvious for everybody. I never rely on

Re: [fpc-pascal] shift right operation with variables

2015-08-17 Thread waldo kitty
On 08/16/2015 09:38 PM, Xiangrong Fang wrote: The output is: 00FF 00FF Why they are different? How can I ensure the result is like SHR with constant. being curious, i tried your program with the same results... then i changed the var name from res to foo with the

Re: [fpc-pascal] shift right operation with variables

2015-08-17 Thread Marco van de Voort
In our previous episode, Xiangrong Fang said: var res: Integer; mask1, mask2: QWord; begin mask1 := $ shr 24; WriteLn(IntToHex(mask1, 16)); res := 24; mask2 := $ shr res; WriteLn(IntToHex(mask2, 16)); end. Why they are different? How can I

Re: [fpc-pascal] shift right operation with variables

2015-08-17 Thread Peter
I was going to comment that the 'bitmask example doesn't work, which it didn’t, but looks like its been recently fixed by adding the needed QWord cast on the '1's. http://wiki.freepascal.org/Bit_manipulation Qwords are certainly trickier to use the Dwords.

Re: [fpc-pascal] shift right operation with variables

2015-08-17 Thread Marco van de Voort
In our previous episode, Peter said: I was going to comment that the 'bitmask example doesn't work, which it didn?t, but looks like its been recently fixed by adding the needed QWord cast on the '1's. http://wiki.freepascal.org/Bit_manipulation Qwords are certainly trickier to use the

[fpc-pascal] shift right operation with variables

2015-08-16 Thread Xiangrong Fang
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 := $ shr 24; WriteLn(IntToHex(mask1, 16)); res := 24; mask2 := $ shr res;