I need a C macro to get the smallest of the two powers exceeding a given number.
For example, FIRSTFREEBIT(0x16) (binary 1_0110 ) should be 0x20 .
I will 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: An algorithm for finding the least power of two greater than or equal to a given value
c bit-manipulation c-preprocessor
18446744073709551615 May 30 '14 at 12:28 2014-05-30 12:28
source share