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)