欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP取進(jìn)制余數(shù)函數(shù)代碼

 更新時(shí)間:2012年01月19日 22:36:00   作者:  
我想知道21712341byte在K位上是多少,M位上、G位呢?這相當(dāng)于進(jìn)制轉(zhuǎn)換的問(wèn)題。只不過(guò)現(xiàn)在要轉(zhuǎn)換的進(jìn)制是1024
復(fù)制代碼 代碼如下:

//取進(jìn)制位上的數(shù)值
function getRemainder($num, $bin, $pos, &$result = 0){
//author lianq.net
//$num 數(shù)值,十進(jìn)制
//$bin 要轉(zhuǎn)換的進(jìn)制
//$pos 位數(shù)
$real_len = log($num, $bin);//對(duì)數(shù),求原值長(zhǎng)度
$floor_len = floor($real_len);//舍去求整
$base = pow($bin, $pos-1);//基數(shù)
$divisor = pow($bin,$pos);//除數(shù)
if($num >= $divisor){
$new_num = $num % pow($bin, $floor_len);
getRemainder($new_num, $bin, $pos, $result);
}else{
$result = floor($num / $base);
}
return $result;
}

//比如,數(shù)值16轉(zhuǎn)換為9進(jìn)制時(shí),它的第一位上的數(shù)值是多少?
$a = getRemainder(16,9, 1);
echo $a;//輸出7

相關(guān)文章

最新評(píng)論