Computing the floor of log₂(x) using only bitwise operators in C
问题 For homework, using C, I'm supposed to make a program that finds the log base 2 of a number greater than 0 using only the operators ! ~ & ^ | + << >> . I know that I'm supposed to shift right a number of times, but I don't know how to keep track of the number of times without having any loops or if s. I've been stuck on this question for days, so any help is appreciated. int ilog2(int x) { x = x | (x >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); x = x | (x >> 16); } This is