/* Returns true if v is a power of 2. * * Uses the algorithm described at * http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */ static inline bool is_power_of_2 (unsigned long v) { return v && ((v & (v - 1)) == 0); }