There is a lot of information on how to find the next power of 2 of a given value (see refs) but I cannot find any to get the previous power of two.
The only way I f
Below code will find the previous power of 2:
int n = 100; n /= 2;//commenting this will gives the next power of 2 n |= n>>1; n |= n>>2; n |= n>>4; n |= n>>16; System.out.println(n+1);