I'm currently in the process of writing a tree enumerator where I've come across the following problem:
I'm looking at masked bitsets, i.e. bitsets where the set bits are a subset of a mask, i.e. 0000101 with mask 1010101. What I want to accomplish is increment the bitset, but only with respect to the masked bits. In this example, the result would be 0010000. To make it a bit clearer, extract only the masked bits, i.e. 0011, increment them to 0100 and distribute them to the mask bits again, giving 0010000.
Does anybody see an efficient way to do this, short of implementing the operation by hand using a combination of bitscans and prefix masks?