bool isPowerOfTwo(int x)
{
// x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
return (x && !(x & (x - 1)));
}
const isPowerOfTow =(num)=>{
if(num === 0){
return false
}
while(num !==1){
num /=2
if(num %2 !==0 && num !== 1){
return false
}
}
return true
}
const isPowerOfTowbitwise =(num)=>{
return num && !(num&(num-1))
}
const powerOfTowRec =(num )=>{
if(num ===0){
return false
}
if(num %2 !== 0 && num !== 1){
return false
}
if(num === 1){
return true
}
return powerOfTowRec(num/2)
}
const nums=[0,1,2,3,4,6,8,9,256,1024]
nums.forEach( num =>{
console.log(num,powerOfTowRec(num))
})