OK, it may sound a bit complicated, but this is what I\'m trying to do :
10101010101
{ 0, 2, 4, 6, 8, 10 }
Here is another suggestion that can be profiled (can be combined with other suggestions for further optimization). Note, the loop here is O(number of set bits)
.
vector bits_set (UINT64 data)
{
UINT n;
vector res;
res.reserve(64);
for (n = 0; data != 0; n++, data &= (data - 1))
{
res.push_back(log2(data & ~(data-1)));
}
return res;
}