新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php怎么將二進(jìn)制轉(zhuǎn)換為十進(jìn)制
本教程操作環(huán)境:windows7系統(tǒng)、php7.1版、DELL G3電腦

php將二進(jìn)制轉(zhuǎn)換為十進(jìn)制
1、使用bindec()函數(shù)
bindec($binary_string) 函數(shù)把二進(jìn)制數(shù)$binary_string轉(zhuǎn)換為十進(jìn)制數(shù)。
";
echo bindec("01") . "
";
echo bindec("11000110011") . "
";
echo bindec("111");
?>
輸出結(jié)果:
2、使用base_convert()函數(shù)
base_convert() 函數(shù)在任意進(jìn)制之間轉(zhuǎn)換數(shù)字。
base_convert($binary_string,$frombase,$tobase);
-
$binary_string 必需。規(guī)定要轉(zhuǎn)換的二進(jìn)制數(shù)。
-
$frombase 必需。規(guī)定數(shù)字原來的進(jìn)制。介于 2 和 36 之間(包括 2 和 36)。高于十進(jìn)制的數(shù)字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。
-
$tobase 必需。規(guī)定要轉(zhuǎn)換的進(jìn)制。介于 2 和 36 之間(包括 2 和 36)。高于十進(jìn)制的數(shù)字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。
"; echo "二進(jìn)制 ".$num2." 轉(zhuǎn)換成十進(jìn)制 ".base_convert($num2,2,10)."
"; ?>
輸出結(jié)果:
名稱欄目:php怎么將二進(jìn)制轉(zhuǎn)換為十進(jìn)制
網(wǎng)頁(yè)URL:http://fisionsoft.com.cn/article/djjdigp.html


咨詢
建站咨詢
