php实现36进制与10进制转换功能示例
发布:smiling 来源: PHP粉丝网 添加日期:2018-11-01 14:29:42 浏览: 评论:0
本文实例讲述了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)."<br>";
- echo"get_num:".get_num('A0ZZ')."<br>";
Tags: 36进制 10进制
相关文章
- ·PHP实现的62进制转10进制,10进制转62进制函数示例(2021-11-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)