in reply to Bitwise & stopped working?

This is the output on my machine (with a 64bit Perl and OS):
c = 97; hash = 61, masked hash = 61 c = 99; hash = 611842, masked hash = 611842 c = 99; hash = 613026f8a1, masked hash = 3026f8a1 c = 101; hash = 3032d2383004, masked hash = d2383004 c = 112; hash = d26bebd7d16c, masked hash = ebd7d16c c = 116; hash = ec11db888a08, masked hash = db888a08

(where the hashes are in hexadecimal, and c in decimal).

I'm not sure if that's the right explanation, but maybe the multiplication of a large number with 2**16 causes an automatic upgraded to floating point numbers on your (32bit) platform.

You can verify this assumption by using Devel::Peek, and Dump the variable $hash after each iteration. It prints (PADMY,IOK,pIOK), and if my guess is right, it will print (PADMY,NOK,pNOK) on your platform.

You could try to avoid that by using strings, and bit shifts instead of multiplications. But I'm sure other monks have more experience with bit manipulation magic than I have. Another (but probably inefficient) solution is to use bigint.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Bitwise & stopped working?
by Krokus (Novice) on May 12, 2010 at 19:01 UTC

    Thanks muchly for the suggestions. It seems that executing the script whilst running a debug build via Visual Studio caused ActiveState's Perl to run rather than the version I was supposed to be using, indicating a path issue. This explains the sudden failure of bitwise AND.

    The notion that $hash is being converted to float appears to stand up; by changing the AND to "% 4294927296", the script works properly in both versions of Perl and all is well in my world again. :D

    Update: Oh, and to further show that it was a float issue, the ActiveState Perl was 32-bit, the version I normally use is indeed a 64-bit build.

      It seems that executing the script whilst running a debug build via Visual Studio caused ActiveState's Perl to run rather than the version I was supposed to be using, indicating a path issue.
      In the future, when something "suddenly stops working" and "I haven't changed anything", look to see if you actually have changed something (like the processing environment).
        In the future, when something "suddenly stops working" and "I haven't changed anything", look to see if you actually have changed something (like the processing environment).

        That is certainly good advice and indeed, in my original post I stated that my first thought was, "well, it must be a result of something I did elsewhere...". In my defense, however, I was not aware that, of the two builds of Perl I had available, one was a 32-bit build and one was a 64-bit build. As well, I had been debugging my application for several hours beforehand with no issues from my scripts. I don't know how my paths suddenly got changed in the middle of a debugging session. I'm still rather bewildered about that. :)

Re^2: Bitwise & stopped working?
by ikegami (Patriarch) on May 12, 2010 at 17:05 UTC

    it will print (PADMY,NOK,pNOK) on your platform.

    Who's pThere?