1 /* Integer base 2 logarithm calculation 2 * 3 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. 4 * Written by David Howells ([email protected]) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 9 * 2 of the License, or (at your option) any later version. 10 */ 11 12 #ifndef _TOOLS_LINUX_LOG2_H 13 #define _TOOLS_LINUX_LOG2_H 14 15 /* 16 * Determine whether some value is a power of two, where zero is 17 * *not* considered a power of two. 18 */ 19 20 static inline __attribute__((const)) 21 bool is_power_of_2(unsigned long n) 22 { 23 return (n != 0 && ((n & (n - 1)) == 0)); 24 } 25 26 #endif /* _TOOLS_LINUX_LOG2_H */ 27