Fonction PHP base_convert()
Exemple
Convertissez un nombre hexadécimal en nombre octal :
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
Définition et utilisation
La fonction base_convert() convertit un nombre d'une base numérique à une autre.
Syntaxe
base_convert(number,frombase,tobase);
Valeurs des paramètres
Parameter | Description |
---|---|
number | Required. Specifies the number to convert |
frombase | Required. Specifies the original base of number. Has 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 35 |
tobase | Required. Specifies the base to convert to. Has 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 35 |
Détails techniques
Valeur de retour : | Le nombre converti dans la base spécifiée |
---|---|
Type de retour : | Chaîne de caractères |
Version PHP : | 4+ |
Plus d'exemples
Exemple
Convertir un nombre octal en nombre décimal :
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
Exemple
Convertissez un nombre octal en nombre hexadécimal :
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮ Référence mathématique PHP