aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index ceced263..b6277f3b 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -512,6 +512,16 @@ void msleep(long miliseconds)
nanosleep(&ts, &ts);
}
+// return 1<<x of highest bit set
+int highest_bit(unsigned long l)
+{
+ int i;
+
+ for (i = 0; l; i++) l >>= 1;
+
+ return i-1;
+}
+
// Inefficient, but deals with unaligned access
int64_t peek_le(void *ptr, unsigned size)
{