Hey guys! Im new to the forums and just started a programming course in college and im having some difficulties. The exercise is as followed:
The binary logarithm of n (log2n) is the power to which the number 2 to must be raised to obtain the value n. Write a C function that calculates log2 of an unsigned integer n using the following approach: find the most significant set bit in n and return the position of this bit. For example, if n is 17 (0b10001), the function should return 4.
The C function should have the following signature:
int mylog2(unsigned int n)
I'm not sure what to do and what "find the most significant set bit in n and return the position of this bit" means. And also how to I can do this, I certainly dont want u guys to do this for me, but some info on how to do it would be appreciated.
I have asked my teacher for help, but he just said read the goddamn books, but I have and still dont know the steps to solve this. Thanks