I want to implement the following function efficently: void check_bits(char* ptr, int length) { for each bit in the array starting at ptr, of length 'length' which is true f(position of bit); } Where the position of bit is it's position compared to the start of the array (so the first bit of *(ptr+2) is at position 16, assuming 8 bits per byte!) I'm currently doing shifting, but this performs poorly for long, sparse arrays. Is there a more efficient method of implementing this, possibly using built-ins? I would assume this is a function other people have implemented before me, but I couldn't find an efficient implementation on the internet. Chris