Copy code The code is as follows:
//Get the numerical value in the base digit
function getRemainder($num, $bin, $pos, &$result = 0){
//author lianq.net
//$num value, decimal
//$bin the base to be converted
//$pos digits
$real_len = log($num, $bin);//Logarithm, find the length of the original value
$floor_len = floor($real_len);//Tear off and round up
$base = pow( $bin, $pos-1);//Base
$divisor = pow($bin,$pos);//Divisor
if($num >= $divisor){
$new_num = $num % pow($bin, $floor_len);
getRemainder($new_num, $bin, $pos, $result);
}else{
$result = floor($num / $base) ;
}
return $result;
}
//For example, when the value 16 is converted to base 9, what is the first digit of it?
$a = getRemainder(16,9, 1);
echo $a;//Output 7
http://www.bkjia.com/PHPjc/324912.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324912.htmlTechArticleCopy code The code is as follows: //Get the numerical value in the base digit function getRemainder($num, $bin, $ pos, //Logarithm, find the length of the original value $floor_len = floor($real_len);//Trop it out to find the integer $base = pow($bin...