I am trying to write a function which returns a value 1 if the number entered is a power of two, else it returns a value 0.
function val = func_1(num)
while not(num == 1)
if num%2~=0
val=0;
break
end
num=num/2;
val=1;
end
end
But unfortunately, the function always return a value 1. Is there any error in the algorithm or the code? Thanks in advance for any help.