PHP base_convert()関数
例
16進数を8進数に変換します。
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
定義と使用法
base_convert()関数は、数値をある基数から別の基数に変換します。
構文
base_convert(number,frombase,tobase);
パラメータ値
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 |
技術的な詳細
戻り値: | 指定されたベースに変換された数 |
---|---|
返品タイプ: | 弦 |
PHPバージョン: | 4歳以上 |
その他の例
例
8進数を10進数に変換します。
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
例
8進数を16進数に変換します。
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
❮PHP数学リファレンス