PHP remainder function code_PHP tutorial

WBOY
Release: 2016-07-21 15:21:29
Original
804 people have browsed it

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

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!