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
Probably the simplest approach (for positive numbers):
// find next (must be greater) power, and go one back p = 1; while (p <= n) p <<= 1; p >>= 1;
You can make variations in many ways if you want to optimize.