jaydee
1
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++)
intTest.setBit(i,true);
int result=-1;
while ((result=intTest.findNextSetBit(++result))!= -1)
{
DBG(String(result));
}
[/code]
?
jules
2
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);
jaydee
3
Thanks Jules, I knew you’d help me out, I completely missed the operator [] !