diff options
Diffstat (limited to 'src/lib/clog2.c')
-rw-r--r-- | src/lib/clog2.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/clog2.c b/src/lib/clog2.c index 41e2af9791..b9b173177c 100644 --- a/src/lib/clog2.c +++ b/src/lib/clog2.c @@ -4,16 +4,19 @@ #include <console/console.h> #endif +/* Assume 8 bits per byte */ +#define CHAR_BIT 8 + unsigned long log2(unsigned long x) { // assume 8 bits per byte. - unsigned long i = 1 << (sizeof(x)*8 - 1); - unsigned long pow = sizeof(x) * 8 - 1; + unsigned long i = 1ULL << (sizeof(x)* CHAR_BIT - 1ULL); + unsigned long pow = sizeof(x) * CHAR_BIT - 1ULL; if (! x) { #ifdef DEBUG_LOG2 printk_warning("%s called with invalid parameter of 0\n", - __FUNCTION__); + __func__); #endif return -1; } |