]> git.sur5r.net Git - cc65/blob - src/cc65/util.c
Avoid a copy of the line contents
[cc65] / src / cc65 / util.c
1 /*
2  * util.c
3  *
4  * Ullrich von Bassewitz, 18.06.1998
5  */
6
7
8
9 #include "util.h"
10
11
12
13 /*****************************************************************************/
14 /*                                   data                                    */
15 /*****************************************************************************/
16
17
18
19
20
21
22 /*****************************************************************************/
23 /*                                   code                                    */
24 /*****************************************************************************/
25
26
27
28 int powerof2 (unsigned long val)
29 /* Return the exponent if val is a power of two. Return -1 if val is not a
30  * power of two.
31  */
32 {
33     int i;
34     unsigned long mask;
35     mask = 0x0001;
36
37     for (i = 0; i < 32; ++i) {
38         if (val == mask) {
39             return i;
40         }
41         mask <<= 1;
42     }
43     return -1;
44 }
45
46
47