|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42694 decbin() is not returning the correct value
Submitted: 2007-09-18 07:08 UTC Modified: 2007-10-02 11:54 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: carrotcake1029 at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.4 OS: Windows Vista Home Premium
Private report: No CVE-ID: None
 [2007-09-18 07:08 UTC] carrotcake1029 at gmail dot com
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-19 13:13 UTC] smlerman at gmail dot com
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.
 [2007-10-02 11:54 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 08:04:05 2022 UTC