sroberts82
Programmer
Hi
I want to do a for loop by bit shift, so I loop through 0,1,2,4,8 etc... 0,1,10,100,1000 etc
So I did this:
for(int i =0x1; i<100; i = i<<1)
{
//do stuff
}
Thats fine, but it leaves out zero. I can't start at zero cos a bit shift on zero is zero. I was thinking if I cut off the least significant bit of i I would get what I want...but I don't know how to do that. Can someone help?
Thanks
I want to do a for loop by bit shift, so I loop through 0,1,2,4,8 etc... 0,1,10,100,1000 etc
So I did this:
for(int i =0x1; i<100; i = i<<1)
{
//do stuff
}
Thats fine, but it leaves out zero. I can't start at zero cos a bit shift on zero is zero. I was thinking if I cut off the least significant bit of i I would get what I want...but I don't know how to do that. Can someone help?
Thanks