PHP 4.0 Bug #6260: xor operator not working correctly
| From: | fredrik at devibe dot net | Date: | Sun, 20 Aug 2000 13:44:58 +0000 |
| Subject: | PHP 4.0 Bug #6260: xor operator not working correctly | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-29911@lists.php.net to get a copy of this message | ||
From: fredrik@devibe.net
Operating system: Linux RedHat 60
PHP version: 4.0.1pl2
PHP Bug Type: Other
Bug description: xor operator not working correctly
I Compiled php with MySQL and apxs.
php.ini shouldn't be relevant. It was not included in the install (btw. why?) and I've
only created one with only session related stuff.
I found this thing on a newsgroup, alt.php, a new group not yet found on many servers, but you *can*
find it on news.cis.dfn.de. The thread is named "a little maths problem", started 08/15/00
11:07.
I've considered it for some time now, and I can't find any explanation:
the code snippet
<?php
$val = 2634023077 ^ 407240870;
echo $val;
?>
outputs "-1740242778".
This can't to my knowledge be correct. I mean, 2634023077 would normally be an unsigned
integer, but I haven't found any way to specify signed/unsigned integers. In addition, the
answer should be 2235957251, and -1740242778 is not the signed representation of that number.
1001 1101 0000 0000 0000 0000 1010 0101 - 2634023077
^ 0001 1000 0100 0110 0000 0000 1010 0110 - 0407240870
= 1000 0101 0100 0110 0000 0000 0000 0011 - 2235957251
The result from an xor operation performed on these two integers in php is
-1740242778. 1740242778 (positive) is in binary:
0110 0111 1011 1001 1111 1111 0101 1010
Then the negative representation should be (negating each bit and "adding" one):
1001 1000 0100 0110 0000 0000 1010 0110
which unsigned is 2554724518, not 2235957251.
All this taken into consideration, is this a bug/flaw or am I wrong?
--Fredrik de Vibe