aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 000000000..b02d077cc
--- /dev/null
+++ b/util.c
@@ -0,0 +1,18 @@
1#include "util.h"
2
3int bitpop(uint8_t bits)
4{
5 int c;
6 for (c = 0; bits; c++)
7 bits &= bits -1;
8 return c;
9}
10
11int biton(uint8_t bits)
12{
13 int n = 0;
14 if (bits >> 4) { bits >>= 4; n += 4;}
15 if (bits >> 2) { bits >>= 2; n += 2;}
16 if (bits >> 1) { bits >>= 1; n += 1;}
17 return n;
18}