To find the base 2 logarithm of a number in Go, we can use the Log2
function from the math
package.
main.go159 chars13 lines
The output of the code above will be:
main.go21 chars2 lines
In this example, we pass the number 8 into the Log2
function and store the result in the logBase2
variable. We then use Printf
to print out the result.
gistlibby LogSnag