★ wanayoo — archive 1999 http://www.php.net/manual/function.base-convert.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Math.
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Math.
* abs
* acos
* asin
* atan
* atan2
* base_convert
* bindec
* ceil
* cos
* decbin
* dechex
* decoct
* deg2rad
* exp
* floor
* getrandmax
* hexdec
* log
* log10
* max
* min
* mt_rand
* mt_srand
* mt_getrandmax
* number_format
* octdec
* pi
* pow
* rad2deg
* rand
* round
* sin
* sqrt
* srand
* tan
Manual: base_convert
View the source code for this pageSearch the site



Previous page
 atan2
 Updated
Sat, 12 Aug 2000
bindec 
Next page


base_convert

(PHP3 >= 3.0.6, PHP4 )

base_convert -- Convert a number between arbitrary bases

Description

strin base_convert (string number, int frombase, int tobase)

Returns a string containing number represented in base tobase. The base in which number is given is specified in frombase. Both frombase and tobase have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 36.

Example 1. Base_convert()


$binary = base_convert ($hexadecimal, 16, 2);


User Contributed Notes: base_convert


scott@mha.ca
08-Sep-1999 03:48
This would seem to be limited to 31 bits, ie. the range of values that can be converted is 0 - 2147483647 in decimal.

Also, this will convert negative values to positive values, unlike DecHex() which will return a null string for negative values.

From what I have observed (using PHP 3.0.11) the following statements will set both a and c to a null string and set b to positive 1.

$a = base_convert (2147483648, 10, 16);
$b = base_convert (-1, 10, 16);
$c = dechex (-1);



tim_converse@yahoo.com
19-Jan-2000 03:05
The explanation says that "z means 36" when it should read "z means 35" (the highest single-digit number in base 36).



tim_converse@yahoo.com
19-Jan-2000 03:24
base_convert expects its string arguments to be integral, and gives nonsensical answers when given floating-point strings. For example, base_convert("1.0", 10, 2) yields "1100100". It seems that "1.0" is being interpreted as "100". (PHP4.0b3).


 About Notes


Previous page
 atan2
 Updated
Sat, 12 Aug 2000
bindec 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.