diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-18 01:30:45 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-27 22:18:00 +0100 |
commit | d722c87f10a965c082055d11adecf312fce367c3 (patch) | |
tree | 7fae6432d9acc4fb75f6e72ec75028b98fab186c | |
parent | 2eb69efa7f912e604092b46d7b12a9bce3ea9995 (diff) | |
download | sparse-d722c87f10a965c082055d11adecf312fce367c3.tar.gz |
add helper is_power_of_2()
Add is_power_of_2() to test if a value is a power of 2.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | bits.h | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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 |