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
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: 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: Fri Apr 19 13:01:30 2024 UTC