您好,登錄后才能下訂單哦!
怎么在php中將36進(jìn)制轉(zhuǎn)換為10進(jìn)制?相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
具體如下:
/** * @desc im:十進(jìn)制數(shù)轉(zhuǎn)換成三十六機(jī)制數(shù) * @param (int)$num 十進(jìn)制數(shù) * return 返回:三十六進(jìn)制數(shù) */ function get_char($num) { $num = intval($num); if ($num <= 0) return false; $charArr = array("0","1","2","3","4","5","6","7","8","9",'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); $char = ''; do { $key = ($num - 1) % 36; $char= $charArr[$key] . $char; $num = floor(($num - $key) / 36); } while ($num > 0); return $char; } /** * @desc im:三十六進(jìn)制數(shù)轉(zhuǎn)換成十機(jī)制數(shù) * @param (string)$char 三十六進(jìn)制數(shù) * return 返回:十進(jìn)制數(shù) */ function get_num($char){ $array=array("0","1","2","3","4","5","6","7","8","9","A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L","M", "N", "O","P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y","Z"); $len=strlen($char); for($i=0;$i<$len;$i++){ $index=array_search($char[$i],$array); $sum+=($index+1)*pow(36,$len-$i-1); } return $sum; }
使用實(shí)例:
echo "get_char:".get_char(514549)."<br>"; echo "get_num:".get_num('A0ZZ')."<br>";
看完上述內(nèi)容,你們掌握怎么在php中將36進(jìn)制轉(zhuǎn)換為10進(jìn)制的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。