简体   繁体   English

C ++中的运算符| =及其用法

[英]Operator |= in C++ and its usage

While i was checking some C++ code i found a rather interesting operator and was wondering what it does? 当我检查一些C ++代码时,我发现了一个相当有趣的运算符,想知道它的作用是什么? I tried finding it on the Internet but no luck. 我尝试在Internet上找到它,但是没有运气。

index |= (image(y - 1, x) != 0) << 3;

The right-hand side is clear, it does a left shift by 3 bit if the result is not zero, but this |= operator on the left confuses me. 右侧很清楚,如果结果不为零,它将向左移动3位,但是左侧的| =运算符使我感到困惑。

In place bitwise OR. 按位或。 It updates the operand with the OR of the operand and the expression on the right. 它使用操作数或右侧的表达式的OR来更新操作数。

Same as 如同

index = index | (image(y - 1, x) != 0) << 3;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM