Bitwise AND for 31-st bit
| From: | Vitalii Demianets | Date: | Tue, 17 May 2011 15:19:41 +0000 |
| Subject: | Bitwise AND for 31-st bit | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-312832@lists.php.net to get a copy of this message | ||
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