]> mj.ucw.cz Git - libucw.git/blob - lib/log2.c
New pattern matching code -- simplified and debugged.
[libucw.git] / lib / log2.c
1 /*
2  *      Sherlock Library -- Binary Logarithm
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8
9 #include "lib.h"
10
11 int
12 ffs(ulg x)
13 {
14   ulg l;
15
16   if (!x)
17         return 0;
18
19   l = 0;
20   if (x & 0xffff0000) l += 16;
21   if (x & 0xff00ff00) l += 8;
22   if (x & 0xf0f0f0f0) l += 4;
23   if (x & 0xcccccccc) l += 2;
24   if (x & 0xaaaaaaaa) l++;
25   return l;
26 }