c++ - 带有双大于运算符的 for 循环声明

标签 c++

<分区>

我在一篇关于“Efficient Integral Image Computation on the GPU”的研究论文中看到了这行代码:

for (int d = n>>1; d>0; d>>=1){...}

(int) n 是一个输入变量。

我总体上熟悉 for 循环和 C++。所以我只能算出 n>>1d>>=1 部分。我以前没见过这个。有人可以提供一个简短的解释吗? 谢谢。

最佳答案

>>> 是右移的按位运算符。

Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.

Source

所以这样:

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/

相关文章:

c++ - 在 C++ 中返回一个字符串

c++ - 长度为零的 char 缓冲区可容纳整数

c++ - 使用 CFileDialog 打开文件失败时如何捕获异常

C++使用gcov和lcov问题?

c++ - 如果其中一个进程意外终止,进程间内存会发生什么情况?

C++ DirectX CreateDevice 从全窗口游戏

c++ - 递归函数周围的 lambda 包装器中的 this-pointer 捕获

c++ - 我的交集检查算法有什么问题?

c++ - 检查字符串是否作为 vector 中的元素存在

c++ - 指针算法和可移植性