什么| =运算符意味着什么 [英] What |= operator means?
问题描述
此运算符的含义(| =)
用于以下示例代码
what this operator means(|=)
used in following sample code
id |= static_cast<quint32>(static_cast<quint8>(data[0] & 0x1F) << 24)
请解释这行代码。如果可能..
我的尝试:
我需要了解运营商,我之前从未使用过。
please explain this line of code. if possible..
What I have tried:
I need to know about operator, which i never used before.
推荐答案
下次尝试谷歌搜索答案。这是个简单的。你只是谷歌的C ++ | =运营商。开始阅读。
在这种情况下,它是两个运营商合二为一。这是一个按位OR操作和一个赋值,如下所示:
Next time try Googling for the answer. This is an easy one. You just Google for "C++ |= operator". Start reading.
In this case, it's two operators in one. It's a bitwise OR operation combined with an assignment, like this:
C |= 2
与
is the same as
C = C | 2
在您的示例中,等效代码为:
In your example, the equivilent code would be:
frame2send.id = frame2send.id | (data[0] & 0xff) << 24;
让我们从一个更简单的例子开始,因为属性并不总是支持这种语法。
Let's start on a more simple example, because properties do not always Support this syntax.
byte theValue= 0;
theValue|= 0x01;
的含义相同:
means the same as:
theValue= theValue | 0x01;
剩下的问题是运算符|意思是:
这意味着对两个论点中的或表示。
现在的问题是有点明智还是:
0或0是0
0或1是1
1或0是1
1或1是1
您可以在上表中看到,只要其中一个参数为1,结果为1。
现在,我假设你知道一个字节是8位,以防万一不要求谷歌。
The remaining question is what does Operator "|" means:
It means bit whise "or" of the two arguments.
Now the question is what means "bit wise or":
0 or 0 is 0
0 or 1 is 1
1 or 0 is 1
1 or 1 is 1
You can maybe see in the table above, as soon as one of the arguments is "1" the result is "1".
Now, I assume you know a byte is 8 bits, in case not ask Google for more.
Arg1 : 0000 0000
Arg2 : 0000 0001
Arg1 | Arg2: 0000 0001
依此类推
为了深入了解这一点,请问Google:
C中的位置操作 - 维基百科,免费的百科全书 [ ^ ]
每个赋值运算符都是相同的。这个
It is the same for every assignment operator. This
id |= something;
表示
means
id = id | something;
C运营商 [ ^ ]查看赋值运算符
你应该提高你对C / C ++基础知识的了解
C编程语言 - 维基百科,免费的百科全书 [ ^ ]
https://hassanolity.files.wordpress.com/2013 /11/the_c_programming_language_2.pdf [ ^ ]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf [ ^ ]
C Operators[^] look at assignment operators
You should sharpen your knowledge of C/C++ basics
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]
这篇关于什么| =运算符意味着什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!