php.net |  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
Votes:1
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: carrotcake1029 at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-18 07:08 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] tony2001@php.net
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 http://www.php.net/support.php 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: Sat Aug 13 09:05:44 2022 UTC