Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1.     /*
  2.      * function to calculate the log 2 of anything
  3.      *
  4.      * does it by getting the log(e)(number)/log(e)(2)
  5.      */
  6.     private int log2(int num) {
  7.         if(num <=0){
  8.             return 0;
  9.         }
  10.         if(!isPowerOfTwo(num)){
  11.             System.out.println("Losing some data when calculating the log2 of: " + num);
  12.         }
  13.         double l1 = Math.log(num);
  14.         double l2 = Math.log(2);
  15.         double result = l1/l2;
  16.         return (int)result;
  17.        
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement