How to get the base 2 (log2) logarithm in PHP

1 Answer

0 votes
function log2($num) {
    return log($num, 2);
}
 
    
$n = 16;
echo log2($n) . "\n";
 
$n = 12;
echo log2($n) . "\n";
 
$n = 10;
echo log2($n) . "\n";


 
 
/*
run:
 
4
3.5849625007212
3.3219280948874
 
*/

 



answered Dec 5, 2021 by avibootz

Related questions

...