It is necessary to create an algorithm that accepts strictly positive n as input and outputs k such that 2 ^ k ≤ n and 2 ^ k + 1> n
Help to make the algorithm, studying in the first year of undergraduate computer science.
The easiest way with If and / or While functions. Not the very first week we were asked this. I do not understand which side to approach to the solution of this issue. Please explain in accessible language, step by step.
2^k ≤ n and 2^k+1 > n
, I am afraid to upset you, a clear description is not. Then, my crystal ball tells you that you need the logarithm function for base 2. And for an explanation why you should contact the lecturer, he probably explained this in the very first lecture (the topic was probably “binary number system”, yes?) - VladD