How to get the next two power of a given number?

advertisements

Possible Duplicate:
bit twiddling: find next power of two

How to obtain the next Power Of Two of a given number?

For example, i receive the number 138, the next POT number is 256.

i receive the number 112, the next POT is 128.

I need to do an algorithm that calculates that

Thanks


A really clever programmer would look at the java.lang.Integer.highestOneBit(int) method, and consider the left-shift operator (<<).