最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

<?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/>";
}

希望本文所述對大家的php程序設計有所幫助。

相關文章

  • php查看網(wǎng)頁源代碼的方法

    php查看網(wǎng)頁源代碼的方法

    這篇文章主要介紹了php查看網(wǎng)頁源代碼的方法,涉及php讀取網(wǎng)頁文件的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • 為你總結一些php信息函數(shù)

    為你總結一些php信息函數(shù)

    PHP語言是一個基于函數(shù)的HTML語言,它龐大的函數(shù)庫可以幫助我們實現(xiàn)許多功能需求。我們在這里為大家詳細介紹了PHP信息函數(shù)包含的一些函數(shù)概念,需要的朋友可以參考下
    2015-10-10
  • php引用地址改變變量值的問題

    php引用地址改變變量值的問題

    看到原始值確實被修改了,發(fā)生在引用之后并被賦值之后,但被賦值之前則原始變量不會改變
    2012-03-03
  • php設計模式 State (狀態(tài)模式)

    php設計模式 State (狀態(tài)模式)

    允許一個對象在其內部狀態(tài)改變時改變它的行為,對象看起來似乎修改了它所屬的類
    2011-06-06
  • 一個簡潔的PHP可逆加密函數(shù)(分享)

    一個簡潔的PHP可逆加密函數(shù)(分享)

    本篇文章是對一個簡潔的PHP可逆加密函數(shù)進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • php實現(xiàn)轉換html格式為文本格式的方法

    php實現(xiàn)轉換html格式為文本格式的方法

    這篇文章主要介紹了php實現(xiàn)轉換html格式為文本格式的方法,通過一個自定義函數(shù)實現(xiàn)針對HTML標簽的過濾,涉及php正則替換的相關操作技巧,需要的朋友可以參考下
    2016-05-05
  • PHP 正則表達式之正則處理函數(shù)小結(preg_match,preg_match_all,preg_replace,preg_split)

    PHP 正則表達式之正則處理函數(shù)小結(preg_match,preg_match_all,preg_replace,pr

    本節(jié)我們就來介紹一下PHP中基于perl的正則表達式處理函數(shù),主要包含了分割, 匹配,查找,替換等等處理操作,依舊是配合示例講解,讓我們開始吧
    2012-10-10
  • Wordpress php 分頁代碼

    Wordpress php 分頁代碼

    Wordpress php 分頁代碼,大家可以參考下。
    2009-10-10
  • PHP循環(huán)與分支知識點梳理

    PHP循環(huán)與分支知識點梳理

    涉及到一些比較復雜的邏輯,分支與循環(huán)是必不可少的。通過分支和循環(huán)的結合使用可以使業(yè)務更加復雜,代碼功能更加強大,這篇文章主要介紹了PHP循環(huán)與分支知識點
    2022-11-11
  • header與緩沖區(qū)之間的深層次分析

    header與緩沖區(qū)之間的深層次分析

    實際的開發(fā)中,大家是否聽說過在header之前不能有任何的實際輸出。甚至有的認為header函數(shù)必須寫在代碼的最前面??墒悄闶欠裨囼炦^header函數(shù)之前輸出東西?下來讓我們更深層次的了解一下
    2016-07-07

最新評論

西青区| 曲松县| 衡水市| 启东市| 三河市| 微山县| 长春市| 安多县| 大港区| 南漳县| 怀远县| 云和县| 湄潭县| 延长县| 富裕县| 修水县| 疏勒县| 大港区| 乐安县| 开平市| 郁南县| 工布江达县| 吉安县| 保靖县| 宜良县| 青阳县| 故城县| 漠河县| 黄浦区| 霞浦县| 哈尔滨市| 阿拉善左旗| 高陵县| 滁州市| 韶山市| 云浮市| 积石山| 博罗县| 大田县| 镇安县| 临汾市|