C
Chris Pruett
An odd (to me) behavior I was hoping someone could explain.
Take the simple command:
perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xFFFF'
I tried this on a number of computers. Most give 0xFFFF, which just
seems wrong. This includes Perl 5.6 and 5.8 on Linux and Darwin (OSX).
Also one Solaris box with 5.0. One computer (Perl 5.6, HPUX) gave what
I thought to be the correct answer (0xB118). Is this some sort of type
conversion issue that trips up the 32-bit PowerPCs and x86s but the
64-bit HPUX avoids?
Interestingly,
perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xBEEF'
0xBEEF
Neat trick. Totally wrong answer, though.
perl -e 'print (0xCEC5 + 0xFFFFE253) & 0xFFFF'
gives 0x10000B118, which I don't understand.
perl -e 'print 0xCEC5 + (0xFFFFE253 & 0xFFFF)'
gives 0x1B118, which makes sense.
Obviously, I'm not grokking the perl bitwise-and (&) operator. The FAQ
warned about accidently anding strings, but stuff like
print oct("0xCEC5") + oct("0xFFFFE253") & oct("0xFFFF")
also gets the wrong answer, so I don't think that's my problem.
Any enlightenment appreciated.
CP
Take the simple command:
perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xFFFF'
I tried this on a number of computers. Most give 0xFFFF, which just
seems wrong. This includes Perl 5.6 and 5.8 on Linux and Darwin (OSX).
Also one Solaris box with 5.0. One computer (Perl 5.6, HPUX) gave what
I thought to be the correct answer (0xB118). Is this some sort of type
conversion issue that trips up the 32-bit PowerPCs and x86s but the
64-bit HPUX avoids?
Interestingly,
perl -e 'print 0xCEC5 + 0xFFFFE253 & 0xBEEF'
0xBEEF
Neat trick. Totally wrong answer, though.
perl -e 'print (0xCEC5 + 0xFFFFE253) & 0xFFFF'
gives 0x10000B118, which I don't understand.
perl -e 'print 0xCEC5 + (0xFFFFE253 & 0xFFFF)'
gives 0x1B118, which makes sense.
Obviously, I'm not grokking the perl bitwise-and (&) operator. The FAQ
warned about accidently anding strings, but stuff like
print oct("0xCEC5") + oct("0xFFFFE253") & oct("0xFFFF")
also gets the wrong answer, so I don't think that's my problem.
Any enlightenment appreciated.
CP