十進(jìn)制(decimal system)轉(zhuǎn)換函數(shù)說明
- 十進(jìn)制轉(zhuǎn)二進(jìn)制 decbin() 函數(shù),如下實(shí)例
echo decbin(12); //輸出 1100
echo decbin(26); //輸出 11010
decbin -- 十進(jìn)制轉(zhuǎn)換為二進(jìn)制
說明 :
string decbin ( int number )
返回一字符串,包含有給定 number 參數(shù)的二進(jìn)制表示蔬崩。所能轉(zhuǎn)換的最大數(shù)值為十進(jìn)制的 4294967295拱层,其結(jié)果為 32 個 1 的字符串。
- 十進(jìn)制轉(zhuǎn)八進(jìn)制 decoct() 函數(shù)
echo decoct(15); //輸出 17
echo decoct(264); //輸出 410
decoct
decoct -- 十進(jìn)制轉(zhuǎn)換為八進(jìn)制
說明
string decoct ( int number )
返回一字符串,包含有給定 number 參數(shù)的八進(jìn)制表示侣颂。所能轉(zhuǎn)換的最大數(shù)值為十進(jìn)制的 4294967295坟乾,其結(jié)果為 "37777777777"迹辐。
- 十進(jìn)制轉(zhuǎn)十六進(jìn)制 dechex() 函數(shù)
echo dechex(10); //輸出 a
echo dechex(47); //輸出 2f
dechex -- 十進(jìn)制轉(zhuǎn)換為十六進(jìn)制
說明
string dechex ( int number )
返回一字符串,包含有給定 number 參數(shù)的十六進(jìn)制表示甚侣。所能轉(zhuǎn)換的最大數(shù)值為十進(jìn)制的 4294967295明吩,其結(jié)果為 "ffffffff"。
二進(jìn)制(binary system)轉(zhuǎn)換函數(shù)說明
- 二進(jìn)制轉(zhuǎn)十六制進(jìn) bin2hex() 函數(shù)
$binary = "11111001";
$hex = dechex(bindec($binary));
echo $hex;//輸出f9
bin2hex -- 將二進(jìn)制數(shù)據(jù)轉(zhuǎn)換成十六進(jìn)制表示
說明
string bin2hex ( string str )
返回 ASCII 字符串殷费,為參數(shù) str 的十六進(jìn)制表示印荔。轉(zhuǎn)換使用字節(jié)方式低葫,高四位字節(jié)優(yōu)先。
- 二進(jìn)制轉(zhuǎn)十制進(jìn) bindec() 函數(shù)
echo bindec('110011'); //輸出 51
echo bindec('000110011'); //輸出 51
echo bindec('111'); //輸出 7
bindec -- 二進(jìn)制轉(zhuǎn)換為十進(jìn)制
說明
number bindec ( string binary_string )
返回 binary_string 參數(shù)所表示的二進(jìn)制數(shù)的十進(jìn)制等價(jià)值仍律。
bindec() 將一個二進(jìn)制數(shù)轉(zhuǎn)換成 integer嘿悬。可轉(zhuǎn)換的最大的數(shù)為 31 位 1 或者說十進(jìn)制的 2147483647水泉。PHP 4.1.0 開始善涨,該函數(shù)可以處理大數(shù)值,這種情況下草则,它會返回 float 類型钢拧。
八進(jìn)制(octal system)轉(zhuǎn)換函數(shù)說明
- 八進(jìn)制轉(zhuǎn)十進(jìn)制 octdec() 函數(shù)
echo octdec('77'); //輸出 63
echo octdec(decoct(45)); //輸出 45
octdec -- 八進(jìn)制轉(zhuǎn)換為十進(jìn)制
說明
number octdec ( string octal_string )
返回 octal_string 參數(shù)所表示的八進(jìn)制數(shù)的十進(jìn)制等值】缓幔可轉(zhuǎn)換的最大的數(shù)值為 17777777777 或十進(jìn)制的 2147483647娶靡。PHP 4.1.0 開始,該函數(shù)可以處理大數(shù)字看锉,這種情況下姿锭,它會返回 float 類型。
十六進(jìn)制(hexadecimal)轉(zhuǎn)換函數(shù)說明
- 十六進(jìn)制轉(zhuǎn)十進(jìn)制 hexdec()函數(shù)
var_dump(hexdec("See"));
var_dump(hexdec("ee"));
// both print "int(238)"
var_dump(hexdec("that")); // print "int(10)"
var_dump(hexdec("a0")); // print "int(160)"
hexdec -- 十六進(jìn)制轉(zhuǎn)換為十進(jìn)制
說明
number hexdec ( string hex_string )
返回與 hex_string 參數(shù)所表示的十六進(jìn)制數(shù)等值的的十進(jìn)制數(shù)伯铣。hexdec() 將一個十六進(jìn)制字符串轉(zhuǎn)換為十進(jìn)制數(shù)呻此。所能轉(zhuǎn)換的最大數(shù)值為 7fffffff,即十進(jìn)制的 2147483647腔寡。PHP 4.1.0 開始焚鲜,該函數(shù)可以處理大數(shù)字,這種情況下放前,它會返回 float 類型忿磅。
hexdec() 將遇到的所有非十六進(jìn)制字符替換成 0。這樣凭语,所有左邊的零都被忽略葱她,但右邊的零會計(jì)入值中。
任意進(jìn)制轉(zhuǎn)換 base_convert() 函數(shù)
$hexadecimal = 'A37334';
echo base_convert($hexadecimal, 16, 2);//輸出 101000110111001100110100
base_convert
base_convert -- 在任意進(jìn)制之間轉(zhuǎn)換數(shù)字
說明
string base_convert ( string number, int frombase, int tobase )
返回一字符串似扔,包含 number 以 tobase 進(jìn)制的表示吨些。number 本身的進(jìn)制由 frombase 指定。frombase 和 tobase 都只能在 2 和 36 之間(包括 2 和 36)炒辉。高于十進(jìn)制的數(shù)字用字母 a-z 表示豪墅,例如 a 表示 10,b 表示 11 以及 z 表示 35黔寇。