复制代码代码如下:
//取进制位上的数值
function getRemainder($num, $bin, $pos, &$result = 0){
//author lianq.net
//$num 数值,十进制
//$bin 要转换的进制
//$pos 位数
$real_len = log($num, $bin);//对数,求原值长度
$floor_len = floor($real_len);//舍去求整
$base = pow($bin, $pos-1);//基数
$divisor = pow($bin,$pos);//除数
if($num >= $divisor){
$new_num = $num % pow($bin, $floor_len);
getRemainder($new_num, $bin, $pos, $result);
}else{
$result = floor($num / $base);
}
return $result;
}
//比如,数值16转换为9进制时,它的第一位上的数值是多少?
$a = getRemainder(16,9, 1);
echo $a;//输出7
http://www.bkjia.com/PHPjc/324912.html
www.bkjia.com
true
http://www.bkjia.com/PHPjc/324912.html
TechArticle
复制代码 代码如下: //取进制位上的数值 function getRemainder($num, $bin, $pos, //对数,求原值长度 $floor_len = floor($real_len);//舍去求整 $base = pow($bin...