ID: 42694
Comment by: smlerman at gmail dot com
Reported By: carrotcake1029 at gmail dot com
Status: Open
Bug Type: Math related
Operating System: Windows Vista Home Premium
PHP Version: 5.2.4
New Comment:
It's most likely because the number you're using is greater than the
maximum for a 32-bit signed integer, resulting in an integer overflow.
Try it with a smaller number and see what happens.
Previous Comments:
------------------------------------------------------------------------
[2007-09-18 07:08:32] carrotcake1029 at gmail dot com
Description:
------------
I wrote my own little function that can take numbers and make turn them
into numbers of other bases. When I ran a few tries with binary, I
began to notice that PHP's decbin() was not matching up with mine.
Easily proven, mine was correct.
Reproduce code:
---------------
echo dec2base(4728937489, 2) . "\n";
echo decbin(4728937489);
function dec2base($int, $base)
{
while ($int >= 1)
{
$ret .= $int % $base;
$int = $int / $base;
}
return strrev($ret);
}
Expected result:
----------------
100011001110111011101110000010001
100011001110111011101110000010001
Actual result:
--------------
100011001110111011101110000010001
11001110111011101110000010001
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42694&edit=1