In article <3F***************@world.std.com>, Bill N1VUX
<wd*@world.std.com> wrote:
perl -e 'print (0xCEC5 + 0xFFFFE253) & 0xFFFF'
gives 0x10000B118, which I don't understand.
This is hexadecimal arithmetic (not maths ;-> ) and the answer is
correct.
However, perl -we will give a warning, which may help the understanding.
The &0xFFFF is applied to the return value of the print.
Thanks for the reply.
Interesting point about the return value of the print. That seems to
explain how I get 0x10000B118 from
perl -e 'print (0xCEC5 + 0xFFFFE253) & 0xFFFF'
I'm still on my quest to get the right answer though (0xB118).
$x = (0xCEC5 + 0xFFFFE253);
print "$x\n";
$x &= 0xFFFF;
print "$x\n"'
4295012632 [0x10000B118]
65535 [0xFFFF]
That's still not the answer I expect.
In the $x &= 0xFFFF, does Perl try to convert the 0x10000B118 to a
native integer type (32-bit), detect the overflow, and saturate the
result (0xFFFFFFFF) before applying the bitwise-and? That would seem
to explain some of the results I'm getting and it might explain why
the 64-bit HPUX version gets the correct number.
CP
--
'When religion and politics ride in the same cart, the whirlwind follows.'