Relative Content

Tag Archive for cperformancebitmapbit-manipulation

Find nth bit index efficiently

Given a bit mask, I’d like to find the index of the nth 1 bit. For example with mask 00001001 and number 1 would return index 3. Same mask with number 0 would return 0. I need to do this as efficiently as possible. The best I came up with is this: