raghu wrote:
>
is it possible to write a code using bitwise operators for checking
whether a number is power of 2 or in general power of n
(n=2,3,4,...)??
int n_is_Power_of_two(long unsigned n)
{
return (n & n - 1) == 0 && n != 0;
}
int n_is_Power_of_four(long unsigned n)
{
return (n & n - 1) == 0 && n % 3 == 1;
}
int n_is_Power_of_eight(long unsigned n)
{
return (n & n - 1) == 0 && n % 7 == 1;
}
--
pete