powerof2 - Man Page
test if a value is a power of 2
Standard C library (libc)
#include <sys/param.h> int powerof2(x);
This macro returns true if x is a power of 2, and false otherwise.
0 is considered a power of 2. This can make sense considering wrapping of unsigned integers, and has interesting properties.
True or false, if x is a power of 2 or not, respectively.
This nonstandard macro is present in glibc and the BSDs.
The arguments may be evaluated more than once.
Because this macro is implemented using bitwise operations, some negative values can invoke undefined behavior. For example, the following invokes undefined behavior: powerof2(INT_MIN);. Call it only with unsigned types to be safe.
2022-12-31 Linux man-pages 6.03