Home > Backend Development > PHP Tutorial > PHP remainder function code_PHP tutorial

PHP remainder function code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:21:29
Original
901 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...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template