w3resource

PHP: base_convert()  function

Description

The base_convert() function is used to convert a number from one base to another.

Version:

(PHP 4 and above)

Syntax:

base_convert (cstring, initial_base, change_base )

Parameters:

Name Description Required /
Optional
Type
cstring The number to convert. Required String
initial_base The initial base. Required integer
new_base The base to convert to. Required integer

Note: Both initial_base and new_base have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented by the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.

Return value:

cstring converted to base new_base.

Value Type: String.

Example:

In the following example base_convert() function converts an hexa number to octal number.

<?php
$hexa = 'E164';
echo base_convert($hexa, 16, 8);
?>

Output:

160544

View the example function in the browser

See also

PHP Function Reference

Previous: atanh
Next: bindec



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/base_convert.php