BigInteger iterator


What’s the best way to iterate over a BigInteger to discover the set bits do you think?

[code] BigInteger intTest;
for (int i=1;i<16;i++)

    int result=-1;
    while ((result=intTest.findNextSetBit(++result))!= -1)




That’d certainly be the most efficient way to do it, but unless performance is critical, I’d probably write it in a less complicated way, e.g.

for (int i = 0; i < bigInt.getHighestBit(); ++i) if (bigInt[i]) DBG (i);


Thanks Jules, I knew you’d help me out, I completely missed the operator [] !