Q. Give one line C expression to check whether a given number is an exponential power of 2
Ans:
if ( x & (x-1) == 0){
printf(“Yes”)
}else{
printf(“No”)
}
What about zero ??
Set the LSB to zero
x = x&x(-1);
When curiosity outbursts …!!!
Q. Give one line C expression to check whether a given number is an exponential power of 2
Ans:
if ( x & (x-1) == 0){
printf(“Yes”)
}else{
printf(“No”)
}
What about zero ??
Set the LSB to zero
x = x&x(-1);