public
/
Ack-5.5.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Pristine Ack-5.5
[Ack-5.5.git]
/
mach
/
sparc
/
ce
/
ce.src
/
misc.c
1
/*
2
misc.c
3
*/
4
5
#include "mach.h"
6
7
int power_of_2(n, ref_exp)
8
int n, *ref_exp;
9
{
10
int exp;
11
12
exp= 0;
13
14
if (n <= 0)
15
return 0;
16
17
while (!(n % 2))
18
{
19
n= n/2;
20
exp++;
21
}
22
if (n != 1)
23
return 0;
24
25
if (ref_exp)
26
*ref_exp= exp;
27
return 1;
28
}
29
30
int uns_power_of_2(n, ref_exp)
31
unsigned n, *ref_exp;
32
{
33
int exp;
34
35
exp= 0;
36
37
if (!n)
38
return 0;
39
40
while (!(n % 2))
41
{
42
n= n/2;
43
exp++;
44
}
45
if (n != 1)
46
return 0;
47
48
if (ref_exp)
49
*ref_exp= exp;
50
return 1;
51
}
52