Posted By

martinB on 11/24/16


Tagged

BitArray


Versions (?)

Fast way to find first set bit in BitArray value


 / Published in: Maxscript
 

Get the first set entry in a BitArray without converting to Array, which can be very slow.

  1. fn getFirstSetBit theArr = (
  2. -- quickly return the first set bit of the bitArray 'theArr'
  3. local first
  4. for n in theArr while (first=n; false) do () -- get first bit on initial loop, then stop while
  5. first
  6. )
  7.  
  8. -- some test code
  9. ba = #{501..600, 12000..99000}
  10. getFirstSetBit ba

Report this snippet  

You need to login to post a comment.