Current location - Training Enrollment Network - Mathematics courses - How to enter a mathematical expression in java: log with radix 2? You can't go directly to math class.
How to enter a mathematical expression in java: log with radix 2? You can't go directly to math class.
To find log2N in java, we must first understand a formula learned in junior high school: log2n = logen/loge2, where logen represents the logarithm of n with the base of e and loge2 represents the logarithm of 2 with the base of e. 。

The log (double A) in the java.lang.math class represents the logarithm of A with E as the base, so log2N is expressed in java as:

log((double)N)/log((double)2)