欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)將任意進(jìn)制數(shù)轉(zhuǎn)換成10進(jìn)制的方法

 更新時(shí)間:2015年04月17日 11:47:50   作者:皮蛋  
這篇文章主要介紹了php實(shí)現(xiàn)將任意進(jìn)制數(shù)轉(zhuǎn)換成10進(jìn)制的方法,涉及php數(shù)制轉(zhuǎn)換的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)將任意進(jìn)制數(shù)轉(zhuǎn)換成10進(jìn)制的方法。分享給大家供大家參考。具體如下:

php將任意進(jìn)制的數(shù)轉(zhuǎn)換成10進(jìn)制,例如8進(jìn)制轉(zhuǎn)換成10進(jìn)制,16進(jìn)制轉(zhuǎn)換成10進(jìn)制

<?php
# Show the steps involved in converting a number 
# from any base (like octal or hex) to base 10
# See below for examples, instructions and copyright
function show_convert_to_base_10 ($number, $base)
{
 // If the number contains a decimal component
 if (strstr ($number, '.'))
 {
  // Get the integer and decimal components
  list ($integer, $decimal) = explode ('.', $number);
 }
 else
 {
  // The number is an integer
  $integer = $number;
 }
  print "<b>Convert the base $base number $number to a
  base 10 number:</b><blockquote>";
  print "Convert the integer component ($integer) of the
   number:<blockquote>";
 // Compute the value of the integer component
 // Loop through the integer digit by digit
 // Reverse the number for easier handling
 $integer = strrev ($integer);
 $length = strlen ($integer);
 for ($pos = 0; $pos < $length; ++$pos)
 {
  /*
   PHP lets you treat strings and numbers like arrays
   Specify an offset and get the character at that
   position
  */
   $digit = $integer[$pos];
  // Handle character values for digits
  // (for bases greater than 10)
  if (eregi ('[a-z]', $digit))
  {
   $digit_value =
     (ord (strtolower ($digit))
     - ord ('a')) + 10;
    $digit = "$digit ($digit_value)";
  }
  else
  {
   $digit_value = $digit;
  }
  // Multiply the current digit by the radix
  // raised to the power of the current position
  $result = $digit_value * pow ($base, $pos);
   print "Multiply the value of the digit at position
    $pos by the value of the radix ($base) raised
    to the power of the position ($pos):<br/>";
   print "$digit * $base<sup>$pos</sup> = $result
    <br/><br/>";
   $sums[] = $result;
 }
 print '</blockquote>';
 if (isset ($decimal))
 {
   print "Convert the decimal component (0.$decimal)
   of the number:<blockquote>";
  // Pad the number with a leading 0 so that we can
  // start at position 1
  $decimal = '0'.$decimal;
  $length = strlen ($decimal);
   for ($pos = 1; $pos < $length; ++$pos) {
   $digit = $decimal[$pos];
   // Handle character values for digits
   // (for bases greater than 10)
   if (eregi ('[a-z]', $digit))
   {
     $digit_value =
     (ord (strtolower ($digit))
     - ord ('a')) + 10;
      $digit = "$digit ($digit_value)";
   }
   else
   {
     $digit_value = $digit;
   }
   // Multiply the current digit by the radix
   // raised to the power of the current position
   $result = $digit_value * pow (1/$base, $pos);
    print "Multiply the value of the digit at
    position $pos by the value of the 1/radix
    ($base) raised to the power of the position
    ($pos):<br/>";
    print "$digit * 1/$base<sup>$pos</sup> =
    $result<br/><br/>";
    $sums[] = $result;
  }
  print '</blockquote>';
 }
 $sums = implode (' + ', $sums);
 eval ("\$base_10_value = $sums;");
  print "</blockquote>The value of the base $base number
  $number in base 10 is $base_10_value. <br/>";
  print "This number is derived from the sum of the values
  of the previous operations ($sums). <br/> <br/>";
}

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • PHP人民幣金額數(shù)字轉(zhuǎn)中文大寫的函數(shù)代碼

    PHP人民幣金額數(shù)字轉(zhuǎn)中文大寫的函數(shù)代碼

    在網(wǎng)上看到一個(gè)非常有趣的PHP人民幣金額數(shù)字轉(zhuǎn)中文大寫的函數(shù),其實(shí)質(zhì)就是數(shù)字轉(zhuǎn)換成中文大寫,測(cè)試了一下,非常有趣,隨便輸個(gè)數(shù)字,就可以將其大寫打印出來(lái),新手朋友們?cè)囈幌掳?/div> 2013-02-02
  • PHP判斷一個(gè)gif圖片是否為動(dòng)態(tài)圖片的方法

    PHP判斷一個(gè)gif圖片是否為動(dòng)態(tài)圖片的方法

    這篇文章主要介紹了PHP判斷一個(gè)gif圖片是否為動(dòng)態(tài)圖片的方法,涉及針對(duì)圖片字節(jié)流中包含數(shù)據(jù)字段的判斷,具有不錯(cuò)的實(shí)用價(jià)值,需要的朋友可以參考下
    2014-11-11
  • php開發(fā)微信支付獲取用戶地址

    php開發(fā)微信支付獲取用戶地址

    微信支付的收貨地址共享功能,主要是統(tǒng)一的管理微信用戶個(gè)人的收貨地址,其收貨地址可以被應(yīng)用于所有可以調(diào)用的開發(fā)者。用戶的收貨地址包含了很多個(gè)人信息,因此該接口必須要通過(guò)申請(qǐng),申請(qǐng)的方式可以在mp平臺(tái)上查看到。
    2015-10-10
  • php靜態(tài)文件生成類實(shí)例分析

    php靜態(tài)文件生成類實(shí)例分析

    這篇文章主要介紹了php靜態(tài)文件生成類,以實(shí)例形式較為詳細(xì)的分析了使用php生成靜態(tài)文件的方法及使用技巧,需要的朋友可以參考下
    2015-01-01
  • PHP程序員最常犯的11個(gè)MySQL錯(cuò)誤小結(jié)

    PHP程序員最常犯的11個(gè)MySQL錯(cuò)誤小結(jié)

    對(duì)于大多數(shù)web應(yīng)用來(lái)說(shuō),數(shù)據(jù)庫(kù)都是一個(gè)十分基礎(chǔ)性的部分。如果你在使用PHP,那么你很可能也在使用MySQL—LAMP系列中舉足輕重的一份子。
    2010-11-11
  • php使用pear_smtp發(fā)送郵件

    php使用pear_smtp發(fā)送郵件

    這篇文章主要介紹了php使用pear_smtp發(fā)送郵件的相關(guān)資料,內(nèi)容很豐富,感興趣的小伙伴們可以參考一下
    2016-04-04
  • php 網(wǎng)頁(yè)播放器用來(lái)播放在線視頻的代碼(自動(dòng)判斷并選擇視頻文件類型)

    php 網(wǎng)頁(yè)播放器用來(lái)播放在線視頻的代碼(自動(dòng)判斷并選擇視頻文件類型)

    其實(shí)這里的php 視頻播放代碼基本上常見的視頻格式都支持,用正則匹配文件擴(kuò)展名,并根據(jù)文件擴(kuò)展名的不同調(diào)用相應(yīng)的在線播放器代碼。
    2010-06-06
  • 使用Codeigniter重寫insert的方法(推薦)

    使用Codeigniter重寫insert的方法(推薦)

    下面小編就為大家?guī)?lái)一篇使用Codeigniter重寫insert的方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • PHP簡(jiǎn)單開啟curl的方法(測(cè)試可行)

    PHP簡(jiǎn)單開啟curl的方法(測(cè)試可行)

    這篇文章主要介紹了PHP簡(jiǎn)單開啟curl的方法,較為詳細(xì)的講述了PHP開啟curl函數(shù)庫(kù)的具體步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-01-01
  • php三種實(shí)現(xiàn)多線程類似的方法

    php三種實(shí)現(xiàn)多線程類似的方法

    這篇文章主要介紹了php三種實(shí)現(xiàn)多線程類似的方法,需要的朋友可以參考下
    2015-10-10

最新評(píng)論