Fast way to find the lowest set bit in a mask?

BlitzMax Forums/BlitzMax Programming/Fast way to find the lowest set bit in a mask?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hey cool. You're the man!

The "n & -n" is interesting, in that it shows what the lowest bit is. It's the conversion from the bit being set to the `number of the bit` which is the hard part. I couldn't figure out any better way to do it so this should be good enough, and much quicker than a loop that searches for bits.

The form:
Local Found:Int=BitToNumber[(Mask & -Mask) * $77cb531 Shr 27]

is good enough for me.

Thanks.