On 03/17/2011 02:04 PM, Alexander Kochetkov wrote:
For my purposes the 'return -1' path will never be taken, so it's not needed. I want to be able to do:
while (bitmap) { i = ctz(bitmap); /* get the LSB index */ bitmap ^= 1<< i; /* zero LSB */
/* for each set bit i... */
}
If there's a faster way to do this I'm all ears.
while (bitmap) { bitmap = (bitmap& (bitmap - 1)); /* zero LSB */
/* for each set bit i... */
}
You could try this solution to zero lsb.
Yes, that's another way to zero the LSB, but I need the index (i).