这篇文章主要介绍了php实现将任意进制数转换成10进制的方法,涉及php数制转换的相关技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了php实现将任意进制数转换成10进制的方法。分享给大家供大家参考。具体如下:
php将任意进制的数转换成10进制,例如8进制转换成10进制,,16进制转换成10进制
Convert the base $base number $number to a base 10 number:
"; print "Convert the integer component ($integer) of the number:The value of the base $base number $number in base 10 is $base_10_value."; // 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 "; print "$digit * $base$pos = $result'; if (isset ($decimal)) { print "Convert the decimal component (0.$decimal) of the number:
"; $sums[] = $result; } print '"; // 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 "; print "$digit * 1/$base$pos = $result'; } $sums = implode (' + ', $sums); eval ("\$base_10_value = $sums;"); print "
"; $sums[] = $result; } print '
希望本文所述对大家的php程序设计有所帮助。