新聞中心
本教程操作環(huán)境:windows7系統(tǒng)、php7.1版、DELL G3電腦

php將二進(jìn)制轉(zhuǎn)為16進(jìn)制字符串的方法:
方法1:使用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,16)."
"; ?>
2、使用bindec()+dechex()函數(shù)
bindec($binary_string) 函數(shù)把二進(jìn)制數(shù)$binary_string轉(zhuǎn)換為十進(jìn)制數(shù)。
dechex($number) 函數(shù)把十進(jìn)制數(shù)$number轉(zhuǎn)換為十六進(jìn)制字符串。
"; echo "二進(jìn)制 ".$num2." 轉(zhuǎn)換成十六進(jìn)制 ".dechex(bindec($num2))."
"; ?>
文章題目:php怎么將二進(jìn)制轉(zhuǎn)為16進(jìn)制字符串
轉(zhuǎn)載來源:http://m.fisionsoft.com.cn/article/cogjpcg.html


咨詢
建站咨詢
