[PATCH 3/6] add helper is_power_of_2()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux