Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java log2

// In Math this holds:  loga(b) = ln(b) / ln(a) // loga is log with base a

public static int log2(int N) {
    // calculate log2 N indirectly
    // using log() method
	int result = (int)(Math.log(N) / Math.log(2));
 
	return result;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #java
ADD COMMENT
Topic
Name
2+2 =