Hello, all!

I've encountered odd behavior of PHP regarding bitwise AND operation when 
dealing with 31-st bit, and kindly ask to give me some pointers.
Consider the following snippet:

$tst1 = (1 << 31);
$tst2 = 0x80000000;
$tst1_eq = $tst1 & 0x80000000;
$tst2_eq = $tst2 & 0x80000000;
print "tst1=$tst1, tst1_eq=$tst1_eq, tst1_type=".gettype($tst1)."\n";
print "tst2=$tst2, tst2_eq=$tst2_eq, tst2_type=".gettype($tst2)."\n";

The output is:

tst1=-2147483648, tst1_eq=0, tst1_type=integer
tst2=2147483647, tst2_eq=2147483647, tst2_type=integer

And I totally can not  understand, why in the hell tst1_eq=0 ?
(BTW I'm using PHP 5.2.14 on 32-bit CPU, if that matters)

Sorry if this is well-known feature and have discussed before. In such a case 
please point me to the URL of the discussion.

Vitalii Demianets

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to