| title | 算法4 Java解答 1.1.14 | ||
|---|---|---|---|
| date | 2019-03-02 19:38:47 +0800 | ||
| draft | false | ||
| tags |
|
||
| categories |
|
Write a static method lg() that takes an int value N as argument and returns the largest int not larger than the base-2 logarithm of N. Do not use Math.
Use while loop to keep dividing the argument by 2 (base was 2), till it reaches zero.
Keep a count on the number of times the division by 2 was been performed.
Return the count - 1 as the program wants the largest integer not larger than log value.