 <p>Another answer assuming IEEE <code>float</code>:</p> <pre><code>int get_bit_index(uint64_t val) { union { float f; uint32_t i; } u = { val }; return (u.i&gt;&gt;23)-127; } </code></pre> <p>It works as specified for the input values you asked for (exactly 1 bit set) and also has useful behavior for other values (try to figure out exactly what that behavior is). No idea if it's fast or slow; that probably depends on your machine and compiler.</p>