php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45415 function "base_convert" bugs
Submitted: 2008-07-02 11:54 UTC Modified: 2008-07-15 01:46 UTC
From: aurorakay at yeah dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.6 OS: Linux 2.6.23-tuxonice-r10-
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: aurorakay at yeah dot net
New email:
PHP Version: OS:

 

 [2008-07-02 11:54 UTC] aurorakay at yeah dot net
Description:
------------
the same data,but at e.g.1,I convert hex to dec. The value is my wish, at e.g.2 I convert dec to hex. The value isn't my wish.


Reproduce code:
---------------
/*e.g.1*/
$flag=1<<29;
$mark="0x808080";
$mark=base_convert($mark,16,10);
$flag=$flag | $mark;
$t=(base_convert($flag,10,2));
/* this will print "string(30) "100000100000001000000010000000" */
var_dump($t);

/*e.g.2*/
$flag1=1<<29;
$mark1="0x808080";
$flag1=base_convert($flag1,10,16);
$flag1=$flag1 | $mark1;
$t1=(base_convert($flag1,16,2));
/* this will print "string(26) "10100000001000000010000000" */
var_dump($t1); 

Expected result:
----------------
/*e.g.1*/ is my wish.

Actual result:
--------------
e.g.1 print "string(30) "100000100000001000000010000000";
e.g.2 print "string(26) "10100000001000000010000000"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-02 11:59 UTC] jani@php.net
Exactly what is the expected and what is the actual results?
 [2008-07-04 11:58 UTC] aurorakay at yeah dot net
Expected result: e.g.1;
Actual result: e.g.1;

example.1 's result is my want. but in examle.2,I want get the example.1's result.but actual, it is  "string(26) "10100000001000000010000000"  I want get "string(30) "100000100000001000000010000000" in example.2;

Excuse my poor english = =
 [2008-07-15 01:46 UTC] jani@php.net
On manual page http://www.php.net/manual/en/language.operators.bitwise.php you can find this comment:

"If both the left- and right-hand parameters are strings, the bitwise operator will operate on the characters' ASCII values."

In your first example they're not both strings but in the second they are..hence the wrong result. This is not a bug -> bogus.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 17:01:31 2024 UTC