PHP½øÖÆת»»ÊµÀý·ÖÎö(2,8,16,36,64½øÖÆÖÁ10½øÖÆÏ໥ת»»)

5年以前  |  阅读数:215 次  |  编程语言:PHP 

±¾ÎÄʵÀý½²ÊoÁËPHP½øÖÆת»»¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º

¿ÉÒÔʵÏÖ£º

10½øÖÆת»»2¡¢8¡¢16¡¢36¡¢62½øÖÆ

2¡¢8¡¢16¡¢36¡¢62½øÖÆת»»10½øÖÆ

ÓеaҪעÒaÏ£¬2¡¢8¡¢16½øÖÆת»»Ê±£¬Ê¹ÓõÄÊÇϵͳµÄ×Ô¼ºµÄº¯Êý¡£

ËuÒÔ£¬²»¹ÜÔoô¸ß¾«¶Èת»»Öµ¿ÉÄÜ´oÓÚ2147483646¡£

ÁiÍa£¬

32½øÖƵ;«×ª»»£¬×i´oÖµ£º2147483646£»
32½øÖƸ߾«×ª»»£¬×i´oÖµ£º77309411327£»
64½øÖƸ߾«×ª»»£¬×i´oÖµ£º133143986175¡£

jinzhi.phpÎļþ£¬×Ô´øÑÝʾ¹¦ÄÜ¡£


    <?php
    $mtime1 = explode(" ", microtime());
    $startTime = $mtime1[0] + $mtime1[1];
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>½øÖÆת»»/title>
    </head>
    <body>
    <form id="jzh" name="jinzhih" method="post" action="">
    <input name="go" type="hidden" value="100">
    <table width="482" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFE8E8" bgcolor="#F4F8FB">
     <tr>
      <td width="194"><select name="jinzhi0" id="jinzhi0">
      <option value="2">2</option>
      <option value="8">8</option>
      <option value="10" selected="selected">10</option>
      <option value="16">16</option>
      <option value="36">36</option>
      <option value="62">62</option>
      </select>
    ½øÖÆ</td>
     <td width="275"><input name="zhi" type="text" id="zhi" /></td>
     </tr>
     <tr>
      <td>½øÐÐ<input name="lx" type="radio" value="0" checked="checked" />
    ÆÕͨ<input type="radio" name="lx" value="1" />¸ß¾«</td><td> </td>
     </tr>
     <tr>
      <td>ת»»Îª
      <select name="jinzhi1" id="jinzhi1">
       <option value="2" selected="selected">2</option>
       <option value="8">8</option>
       <option value="10">10</option>
       <option value="16">16</option>
       <option value="36">36</option>
       <option value="62">62</option>
      </select>½øÖÆ£¬</td><td>×ܳ¤¶ÈΪ
      <input name="changdu" type="text" id="changdu" value="10" size="4" maxlength="2" />
    ×Ö*u¡£</td></tr><tr>
     <td><input type="submit" name="Submit" value="Ìa½»" /></td>
     <td><input type="reset" name="Submit2" value="ÖØÖÃ" /></td>
     </tr></table>
     <p>×¢Òa£º½oÄܽøÐÐ10½øÖÆת»»Îª2¡¢8¡¢16¡¢36¡¢62½øÖÆ£»»o*´×ª»»¡£</p></form>
    <?php
    class jinzhi_class
    {
       //10½øÖÆת2¡¢8¡¢16¡¢36¡¢62½øÖÆ
       function jinzhih_0($shu,$jinzhi,$w)
       {
       $zifu = "";
       while ($shu!=0){
       $linshi = $shu%$jinzhi;
       switch ($jinzhi){
        case 2:
         $zifu = decbin($shu);
         return $zifu;
        case 8:
         $zifu = decoct($shu);
         return $zifu;
        case 16:
         $zifu = dechex($shu);
         return $zifu;
        case 36:
         if ($linshi>=10)
         {
         $zifu.= chr(($linshi+55));
         }else{
          $zifu.= $linshi;}
         break;
        case 62:
         if (($linshi>=10) && ($linshi36)) {$zifu.= chr($linshi+55);break;}
         if (($linshi>=36) && ($linshi62)) {$zifu.= chr($linshi+61);break;}
         $zifu.= $linshi;break;
       default:
       $zifu.= $linshi;
       break;
       }
       $shu = intval($shu/$jinzhi);
       }
       for ($i=strlen($zifu);$i$w;$i++)
       $zifu.="0";
      return strrev($zifu);}
       //2¡¢8¡¢16¡¢36¡¢62½øÖÆת10½øÖÆ
       function jinzhih_1($zifu,$jinzhi,$w)
     { $shu=0;
      for ($i=0;$i=strlen($zifu)-1;$i++)
         {
         $linshi = substr($zifu,$i,1);
         switch ($jinzhi){
          case 2:
           $shu = bindec($zifu);
           $i=strlen($zifu)+1;
           break;
          case 8:
           $shu = octdec($zifu);
          $i=strlen($zifu)+1;
          break;
          case 16:
           $shu = hexdec($zifu);
           $i=strlen($zifu)+1;
           break;
         case 36:
          if (ord($linshi)=57)
          {$shu+=(ord($linshi)-48)*pow($jinzhi,strlen($zifu)-$i-1);
         }else{
           $shu=$shu + (ord($linshi)-55)*pow($jinzhi,strlen($zifu)-$i-1);}
           break;
         case 62:
          if (ord($linshi)=57)
          {$shu+=$linshi*pow($jinzhi,strlen($zifu)-$i-1);     
         }elseif ((ord($linshi)>=65) && (ord($linshi)=90)){
          $shu+= (ord($linshi)-55)*pow($jinzhi,strlen($zifu)-$i-1);
          }else{
          $shu+= (ord($linshi)-61)*pow($jinzhi,strlen($zifu)-$i-1);}
          break;
         }
       }
       return $shu;
       }
       //10½øÖƸ߾«¶Èת»»2¡¢8¡¢16¡¢36¡¢62½øÖÆ
       function jinzhih_G0($shu,$jinzhi,$w)
       {
       $zifu = "";
       while ($shu!=0){
       $linshi = bcmod($shu,$jinzhi);
       switch ($jinzhi){
        case 2:
         $zifu = decbin($shu);
         return $zifu;
        case 8:
         $zifu = decoct($shu);
         return $zifu;
        case 16:
         $zifu = dechex($shu);
         return $zifu;
        case 36:
         if ($linshi>=10)
         {
         $zifu.= chr(($linshi+55));
         }else{
          $zifu.= $linshi;}
         break;
        case 62:
         if (($linshi>=10) && ($linshi36)) {$zifu.= chr($linshi+55);break;}
         if (($linshi>=36) && ($linshi62)) {$zifu.= chr($linshi+61);break;}
         $zifu.= $linshi;break;
       default:
       $zifu.= $linshi;
       break;
       }
       $shu = intval(bcdiv($shu,$jinzhi));
       }
       for ($i=strlen($zifu);$i$w;$i++)
       $zifu.="0";
      return strrev($zifu);}
       //2¡¢8¡¢16¡¢36¡¢62½øÖƸ߾«¶Èת»»10½øÖÆ
       function jinzhih_G1($zifu,$jinzhi,$w)
     { $shu= "";
      for ($i=0;$i=strlen($zifu)-1;$i++)
         {
         $linshi = substr($zifu,$i,1);
         switch ($jinzhi){
          case 2:
           $shu = bindec($zifu);
           $i=strlen($zifu)+1;
           break;
          case 8:
           $shu = octdec($zifu);
          $i=strlen($zifu)+1;
          break;
          case 16:
           $shu = hexdec($zifu);
           $i=strlen($zifu)+1;
           break;
         case 36:
          if (ord($linshi)=57)
          {$shu=bcadd($shu,bcmul((ord($linshi)-48),bcpow($jinzhi,strlen($zifu)-$i-1)));
         }else{
           $shu=bcadd($shu,bcmul((ord($linshi)-55),bcpow($jinzhi,strlen($zifu)-$i-1)));}
           break;
         case 62:
          if (ord($linshi)=57)
          {$shu=bcadd($shu,bcmul($linshi,bcpow($jinzhi,strlen($zifu)-$i-1)));
         }elseif ((ord($linshi)>=65) && (ord($linshi)=90)){
          $shu=bcadd($shu,bcmul((ord($linshi)-55),bcpow($jinzhi,strlen($zifu)-$i-1)));
          }else{
          $shu=bcadd($shu,bcmul((ord($linshi)-61),bcpow($jinzhi,strlen($zifu)-$i-1)));
          }
          break;
         }
       }
       return $shu;}
    }
    if (isset($_GET["p"]))
    {if ($_GET["p"]==="1"){
    echo "";
    echo "Ìaʾ£º
    ";
    echo "32½øÖƵ;«×ª»»£¬×i´oÖµ£º2147483646
    ";
    echo "32½øÖƸ߾«×ª»»£¬×i´oÖµ£º77309411327
    ";
    echo "64½øÖƸ߾«×ª»»£¬×i´oÖµ£º133143986175
    ";
    echo "";
    echo "ֵΪ£º";
    $Fs = new jinzhi_class();
    if ($_POST['lx']=="0" && $_POST['jinzhi0']=="10")
    {echo $Fs->jinzhih_0($_POST['zhi'],$_POST['jinzhi1'],$_POST['changdu'])."
    ";}
    if ($_POST['lx']=="1" && $_POST['jinzhi0']=="10")
    {echo $Fs->jinzhih_G0($_POST['zhi'],$_POST['jinzhi1'],$_POST['changdu']);}
    if ($_POST['lx']=="0" && $_POST['jinzhi0']>"10")
    {echo $Fs->jinzhih_1($_POST['zhi'],$_POST['jinzhi0'],$_POST['changdu']);}
    if ($_POST['lx']=="1" && $_POST['jinzhi0']>"10")
    {echo $Fs->jinzhih_G1($_POST['zhi'],$_POST['jinzhi0'],$_POST['changdu']);}
    }
    echo "";}
    $mtime1 = explode(" ", microtime());
    $endTime = $mtime1[0] + $mtime1[1];
    printf ("Ò³ÃaeÖ´ÐÐʱ¼a£º%.6fs.",$endTime-$startTime);
    ?>

PS£ºÕaÀiÔÙΪ´o¼ÒÍƼo¼¸¿i¼ÆËaÓeת»»¹¤¾ß¹(C)´o¼Ò²Î¿¼Ê¹Óãº

ÔÚÏßÈÎÒa½øÖÆת»»¹¤¾ß£º
http://tools.jb51.net/transcoding/hexconvert

¿Æѧ¼ÆËaÆ÷ÔÚÏßʹÓÃ_¸ß¼¶¼ÆËaÆ÷ÔÚÏß¼ÆËa£º
http://tools.jb51.net/jisuanqi/jsqkexue

ÔÚÏß¼ÆËaÆ÷_±e×¼¼ÆËaÆ÷£º
http://tools.jb51.net/jisuanqi/jsq

¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶PHPÊýѧÔËËa¼¼ÇÉ×ܽa¡¡¢¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶PHPÊý¾Ý½a¹¹ÓeËa*¨½Ì³Ì¡¡¢¡¶[php³ÌÐoÉe¼ÆËa¨×ܽa](http://www.jb51.net/Special/111.htm)¡¡¢¡¶[PHPÔËËaÓeÔËËauÓè×ܽa](http://www.jb51.net/Special/357.htm)¡¡¢¡¶php×Öu´®(string)Óè×ܽa¡¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡

Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例