Most efficient way to find the index of the only '1' bit in a char variable (in C)
问题 This is an interview question: You are given a char variable named ch , when you know that it represents a number that in its binary form, only one of its eight bits will be equal to '1'. I.E. , the only possible values for ch are: 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 . Given the variable ch , I need to write the most efficient code to get the index of that '1' bit. For example: if ch == 0x1 -> result is 0. if ch == 0x4 -> result is 2. The obvious way is to use switch-case, but I need