Função PHP base_convert()
❮ Referência matemática do PHP
Exemplo
Converter um número hexadecimal em número octal:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
Definição e uso
A função base_convert() converte um número de uma base numérica para outra.
Sintaxe
base_convert(number,frombase,tobase);
Valores de parâmetro
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 |
Detalhes técnicos
Valor de retorno: | O número convertido para a base especificada |
---|---|
Tipo de retorno: | Corda |
Versão do PHP: | 4+ |
Mais exemplos
Exemplo
Converter um número octal em um número decimal:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
Exemplo
Converter um número octal em um número hexadecimal:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮ Referência matemática do PHP