<分区>
我在一篇关于“Efficient Integral Image Computation on the GPU”的研究论文中看到了这行代码:
for (int d = n>>1; d>0; d>>=1){...}
(int) n 是一个输入变量。
我总体上熟悉 for 循环和 C++。所以我只能算出 n>>1
和 d>>=1
部分。我以前没见过这个。有人可以提供一个简短的解释吗?
谢谢。
标签 c++
<分区>
我在一篇关于“Efficient Integral Image Computation on the GPU”的研究论文中看到了这行代码:
for (int d = n>>1; d>0; d>>=1){...}
(int) n 是一个输入变量。
我总体上熟悉 for 循环和 C++。所以我只能算出 n>>1
和 d>>=1
部分。我以前没见过这个。有人可以提供一个简短的解释吗?
谢谢。
最佳答案
>>>
是右移的按位运算符。
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.
所以这样:
n >> 1
会将 n
的所有位向右移动 1 位。
>>=
is a right shift assignment operator. It takes that value stored in i and shifts all it's bits to the right 1 place (with the leftmost bit being set to 0)
结果是:
d >>= 1
等同于:
d = d >> 1;
关于c++ - 带有双大于运算符的 for 循环声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44200014/