最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php实现36进制与10进制转换功能示例
时间:2022-06-24 17:44:44 编辑:袖梨 来源:一聚教程网
本文实例讲述了php实现36进制与10进制转换功能。分享给大家供大家参考,具体如下:
代码如下 | 复制代码 |
/** * @desc im:十进制数转换成三十六机制数 * @param (int)$num 十进制数 * return 返回:三十六进制数 */ functionget_char($num) { $num=intval($num); if($num<= 0) returnfalse; $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:三十六进制数转换成十机制数 * @param (string)$char 三十六进制数 * return 返回:十进制数 */ functionget_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; } |
使用实例:
代码如下 | 复制代码 |
echo"get_char:".get_char(514549)." echo"get_num:".get_num('A0ZZ')." |
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21