I should have mentioned. This function asumes that the input n is not equal to 0.<div><br></div><div>You can use it or a nicely ByteArray#&#39;d and uncheckedShiftRL64#&#39;d version together with the iterated masking of bits to walk through the bits in order.<br>
<br>-Edward<br><br><div class="gmail_quote">On Sun, Sep 18, 2011 at 5:07 PM, Edward Kmett <span dir="ltr">&lt;<a href="mailto:ekmett@gmail.com">ekmett@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
There are some neat tricks you can use using deBruijn multiplication to optimize finding the least significant set bit.<div><br></div><div>My geometric coalgebra code in <a href="https://github.com/ekmett/algebra/blob/master/Numeric/Coalgebra/Geometric.hs#L72" target="_blank">https://github.com/ekmett/algebra/blob/master/Numeric/Coalgebra/Geometric.hs#L72</a> uses the following:</div>

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;background-color:transparent"><br>
</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;background-color:transparent">
which could be sped up slightly by using a byteArray# directly for the backing store to find the least significant set bit in a Word64.</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:1em;background-color:transparent">