这行代码是做什么的?
对此代码的作用感到困惑
for (L=0; L < levels; L++, N_half>>=1){
func( y, N_half);
} // end: levels for loop
特别是这个“ N_half>>=1 ”
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它通过在每次迭代时将 N_half 除以二来推进循环。 它相当于:
It advances the loop by dividing N_half by two at every iteration. It is equivalent to:
N_half>>=1
对 N_half 执行 1 位按位右移,这(对于非负数)将其除以 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+
.>>= 运算符将数字的数字向右移动 k 位
示例:
二进制形式
通常十进制形式
,内存中的数字为二进制形式,>>=1 相当于除以 2 。
>>= operator shifts number's digits k positions at right
examples:
binary form
decimal form
as usual, the numbers in memory are in binary form and >>=1 is equivalent to division by 2.
如果 N_half 是正整数或无符号整数,则将其减半。
If N_half is a positive or unsigned integer, it halves it.
它将 N_half 右移 1(即将其除以二)并将结果存储回 N_half
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
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:
Caveats: