Index of single bit in long integer (in C) [duplicate]
问题 This question already has answers here : Bit twiddling: which bit is set? (15 answers) Closed 7 years ago . I am trying to find an optimal code to locate a single bit index in a long integer (64 bit). The long integer has exactly one set bit. (Using C language) Currently, I am just shifting the whole thing by one bit, then checking for zero. I have read about lookup tables, but it won't do for the whole 64 bits. I thought about checking each 8 bits for zero, if not use a lookup, but still I