util: Utility function to check if a number is a power of two.

This commit is contained in:
José Fonseca
2009-09-07 14:21:51 +01:00
parent 8be72bb764
commit 6b129a8222
+10
View File
@@ -340,6 +340,16 @@ util_is_inf_or_nan(float x)
}
/**
* Test whether x is a power of two.
*/
static INLINE boolean
util_is_pot(unsigned x)
{
return (x & (x - 1)) == 0;
}
/**
* Find first bit set in word. Least significant bit is 1.
* Return 0 if no bits set.