ack/mach/sparc/ce/ce.src/misc.c
1991-10-04 10:37:06 +00:00

53 lines
452 B
C

/*
misc.c
*/
#include "mach.h"
int power_of_2(n, ref_exp)
int n, *ref_exp;
{
int exp;
exp= 0;
if (n <= 0)
return 0;
while (!(n % 2))
{
n= n/2;
exp++;
}
if (n != 1)
return 0;
if (ref_exp)
*ref_exp= exp;
return 1;
}
int uns_power_of_2(n, ref_exp)
unsigned n, *ref_exp;
{
int exp;
exp= 0;
if (!n)
return 0;
while (!(n % 2))
{
n= n/2;
exp++;
}
if (n != 1)
return 0;
if (ref_exp)
*ref_exp= exp;
return 1;
}