PHP中進制之間的互相轉換

 常見的進制:

二進制      binary        ----->  binphp

八進制      octal          ----->  octhexo

十進制      decimal      ----->  dec函數

十六進制   hexadecimal     ----->  hexpost

 

php提供了幾常見進制之間轉換的函數spa

二進制轉爲其餘進制code

binoct();//轉爲八進制blog

bindec();//轉爲十進制ci

binhex();//轉爲十六進制string

八進制轉爲其餘進制it

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 = '123456';//十進制echo base_convert($hexadecimal, 10, 5);//轉爲五進制

相關文章
相關標籤/搜索