Created
January 1, 2017 13:30
-
-
Save enif-lee/24739f080ccb3b87b7eae46cf29d370e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LogUtil { | |
static int log2 (int number) { | |
int logCount = 0; | |
if(65536 <= number) { logCount += 16; number >>= 16; } | |
if(256 <= number) { logCount += 8; number >>= 8; } | |
if(16 <= number) { logCount += 4; number >>= 4; } | |
if(4 <= number) { logCount += 2; number >>= 2; } | |
return logCount + (2 <= number ? 1 : 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment