Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * function to calculate the log 2 of anything
- *
- * does it by getting the log(e)(number)/log(e)(2)
- */
- private int log2(int num) {
- if(num <=0){
- return 0;
- }
- if(!isPowerOfTwo(num)){
- System.out.println("Losing some data when calculating the log2 of: " + num);
- }
- double l1 = Math.log(num);
- double l2 = Math.log(2);
- double result = l1/l2;
- return (int)result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement