Add is_power_of_2() to test if a value is a power of 2. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- bits.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bits.h b/bits.h index c0dc952eaed9..63a663c248e4 100644 --- a/bits.h +++ b/bits.h @@ -58,4 +58,9 @@ static inline long long bits_extend(long long val, unsigned size, int is_signed) return val; } +static inline int is_power_of_2(long long val) +{ + return val && !(val & (val - 1)); +} + #endif -- 2.29.2