Hi
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
Hi
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
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) {
...
}
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 +
.
It right shifts N_half by 1 (i.e. divides it by two) and stores the result back in N_half
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:
>>= 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.