Funkce PHP base_convert().
Příklad
Převeďte hexadecimální číslo na osmičkové:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
Definice a použití
Funkce base_convert() převádí číslo z jednoho číselného základu na jiný.
Syntax
base_convert(number,frombase,tobase);
Hodnoty parametrů
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 |
Technické údaje
Návratová hodnota: | Číslo převedené na zadaný základ |
---|---|
Typ vrácení: | Tětiva |
Verze PHP: | 4+ |
Další příklady
Příklad
Převeďte osmičkové číslo na desítkové:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
Příklad
Převeďte osmičkové číslo na hexadecimální číslo:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮ PHP Math Reference