PHP base_convert() Funzione
Esempio
Converti un numero esadecimale in un numero ottale:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
Definizione e utilizzo
La funzione base_convert() converte un numero da una base numerica a un'altra.
Sintassi
base_convert(number,frombase,tobase);
Valori dei parametri
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 |
Dettagli tecnici
Valore di ritorno: | Il numero convertito nella base specificata |
---|---|
Tipo di reso: | Corda |
Versione PHP: | 4+ |
Altri esempi
Esempio
Converti un numero ottale in un numero decimale:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
Esempio
Converti un numero ottale in un numero esadecimale:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮ Riferimento matematico PHP