php实现将任意进制数转换成10进制的方法_PHP
程序员文章站
2022-05-08 16:03:22
...
本文实例讲述了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 '
"; print "This number is derived from the sum of the values of the previous operations ($sums).
"; }
希望本文所述对大家的php程序设计有所帮助。
上一篇: JavaScript中特性和属性的区别
下一篇: php/js汉字正则表达式总结