title: Bit twiddling: which bit is set?
body: <p>I have a 64-bit unsigned integer with exactly 1 bit set. I’d like to assign a value to each of the possible 64 values (in this case, the odd primes, so 0x1 corresponds to 3, 0x2 corresponds to 5, …, 0x8000000000000000 corresponds to 313).</p>
  <p>It seems like the best way would be to convert 1 → 0, 2 → 1, 4 → 2, 8 → 3, …, 2<sup>63</sup> → 63 and look up the values in an array. But even if that’s so, I’m not sure what the fastest way to get at the binary exponent is. And there may be more efficient ways, still.</p>
  <p>This operation will be used 10<sup>14</sup> to 10<sup>16</sup> times, so performance is a serious issue.</p>