Compute Binary Logarithm
Examples
Filter
console.log(Math.log2(3));
// expected output: 1.584962500721156
console.log(Math.log2(2));
// expected output: 1
console.log(Math.log2(1));
// expected output: 0
console.log(Math.log2(0));
// expected output: -Infinity
Math.log2(3); // 1.584962500721156
Math.log2(2); // 1
Math.log2(1); // 0
Math.log2(0); // -Infinity
Math.log2(-2); // NaN
Math.log2(1024); // 10
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("%.1f", math.Log2(256))
}