KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
If I have a number a , I want the value of x in b =2^ x , where b is the next power of 2 greater than a . In case you missed the tag, this is Java, and a is an int. I'm looking for the fastest way to do this. My solution thusfar is to use bit-twiddling to get b , then do (int)(log( b )/log(2)), but I feel like there has to be a faster method that doesn't involve dividing two floating-point numbers.
Tags (comma-separated)
Save Edits
Cancel