简体   繁体   English

C#运算符“ >> =”-它是如何工作的?

[英]C# the operator “>>=” - How does it work?

I wonder what the ">>=" operator in C# does. 我想知道C#中的“ >> =”运算符是做什么的。 Can anyone tell me? 谁能告诉我?

It's the right-shift assignment operator. 它是右移赋值运算符。 From MSDN: 从MSDN:

An expression of the form 形式的表达

x >>= y

is evaluated as 被评估为

x = x >> y

except that x is only evaluated once. 除了x仅被评估一次。 The >> operator shifts x right by an amount specified by y. >>运算符将x右移y指定的数量。

>>= Operator (C# Reference) >> =运算符(C#参考)

x >>= y is the same as doing x = x >> y x >> = y与x = x >> y相同

It's just like += but with bit shifting operators. 就像+ =一样,但带有移位运算符。

Like C, 像C一样

x >>= y

is the same as: 是相同的:

x = x >> y

This is similar to all the other op= operators like += and /= . 这类似于+=/=所有其他op=运算符。 The >> operator is bit shifting to the right. >>运算符向右移。

For example, the variable x with decimal value 50 10 (in binary, 00110010 10 ) can be bit-shifted two bits right with: 例如,十进制值50 10 (二进制, 00110010 10 )的变量x可以右移两位:

x >>= 2

and it will become 00001100 2 , or 12 10 . 它将变为00001100 212 10

>>= is a bitshift to the "right". >>=是向右移的位。 eg you have a integer variable containing the value 4. It is coded in binary 100. After the operation i >>= 1 the variable contains the value 2 (coded in binary 10). 例如,您有一个包含值4的整数变量。它以二进制100编码。在i >>= 1操作之后,变量包含值2(以二进制10编码)。

 int i = 4;
 i >>= 1;
 // i is 2 now

"x >>= y" is equivalent to "x = x >> y"
see also: 也可以看看:
http://sharpertutorials.com/c-operator-list/ http://sharpertutorials.com/c-operator-list/

x>>=y只是x = x >> y一种更短的表达方式...您将x向右移动y位。

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

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