View Single Post
Old Jul 27th, 2007, 3:27 PM   #8
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
And I do have another question. Another way to write the for header would be to do something like this:

for (; mask != 0; mask >>>= 1)

I have 3 questions about the way this header is working:

1. There is no initialization in the for loop header. Is this because in this particular program, it's simply not needed? This is my guess anyway.

2. The mask != 0 part. This must mean that when the 1 in the mask finally gets shifted out(it falls off the right end) then the mask in effect has the value of zero. In this case this would cause the loop to end. Again, this is my best guess.

3. The mask >>>= 1 part. Here we are using the unsigned right shift instead of the regular >> right shift operator. My understanding is that when you use the unsigned right shift operator it will not preserve the sign bit, so it will bring in a 0 on the left. If I instead used the right shift operator this would cause the compiler to bring in a 1 on the left so my mask would look like this:

1100 0000

It would look like that after the first shift. And that would screw up the program then? Again, that's my guess.

Last edited by 357mag; Jul 27th, 2007 at 3:28 PM. Reason: mistake
357mag is offline   Reply With Quote