常見的進制:php
二進制 binary -----> binhexo
八進制 octal -----> oct函數
十進制 decimal -----> decspa
十六進制 hexadecimal -----> hexcode
php提供了幾常見進制之間轉換的函數ci
二進制轉爲其餘進制string
binoct();//轉爲八進制class
bindec();//轉爲十進制二進制
binhex();//轉爲十六進制im
八進制轉爲其餘進制
octbin();//轉爲二進制
octdec();//轉爲十進制
octhex();//轉爲十六進制
十進制轉爲其餘進制
decbin();//轉爲二進制
decoct();//轉爲八進制
dechex();轉爲十六進制
十六進制轉爲其餘進制
hexbin();轉爲二進制
hexoct();//轉爲八進制
hexdec();//轉爲十六進制
上面列舉了這麼多,其實本身感受一點用沒有,對於上面的這些函數,你只須要急着bin、oct、dec、hex就能夠了,你要把a進制轉爲b進制,那就是ab()
舉個簡單的例子:
把二進制(bin)轉爲十進制(dec): bindec();
就這麼簡單
但這樣可能還不能知足咱們的需求,因而php有個咱們提供了一個真正實現愛咋轉就咋轉的函數:base_convert();
base_convert() 該函數有三個參數
string base_convert ( string $number
, int $frombase
, int $tobase
)
舉個列子:$hexadecimal = '125458';//十進制echo base_convert($hexadecimal, 10, 5);//轉爲五進制