Reputation:
Confused as to what this code does
for (L=0; L < levels; L++, N_half>>=1){
func( y, N_half);
} // end: levels for loop
In particular this " N_half>>=1 "
Thanks
Upvotes: 1
Views: 394
Reputation: 13163
This seems to be the same as
for (L=0; L < levels; L++)
{
func(y, N_Half);
N_Half /= 2;
}
The question has been rephrased since I answered it, such that this is no longer valid, but added for completeness: If nothing else is done within the loop, it is equivalent to:
N_Half >>= levels;
Caveats:
Upvotes: 0
Reputation: 43110
>>= operator shifts number's digits k positions at right
examples:
binary form
N = 101010111 // 2-base arithmetic system
N >>= 1; // `division` by 2
N: 010101011
decimal form
N = 123456 // 10-base arithmetic system
N >>= 2; // `division` by 10^2
N: 001234
as usual, the numbers in memory are in binary form and >>=1 is equivalent to division by 2.
Upvotes: 1
Reputation: 2361
It right shifts N_half by 1 (i.e. divides it by two) and stores the result back in N_half
Upvotes: 0
Reputation: 124297
N_half>>=1
performs a 1-place bitwise shift-right on N_half, which (for non-negative numbers) divides it by 2.
>>=
is to >>
as +=
is to +
.
Upvotes: 5
Reputation: 59563
It advances the loop by dividing N_half by two at every iteration. It is equivalent to:
for (L=0; L<levels; ++L, N_half=N_half / 2) {
...
}
Upvotes: 9