I need a C macro to get the smallest of power two greater than a given number.
For example, FIRSTFREEBIT(0x16)
(binary 1_0110
) must be equal to 0x20
.
I am going to use it as:
#include <someheader.h> // defines SOME_X and SOME_Y
enum {
x = SOME_X,
y = SOME_Y,
z = FIRSTFREEBIT(x|y),
t = z << 1,
};
A similar, but slightly different SO question: Algorithm for finding the smallest power of two that's greater or equal to a given value