>>在C#中的含义

Geo*_*rge -5 c# syntax

也许这是一个愚蠢的问题,但我无法通过键入代码来搜索google/stackoverflow中的任何结果.

我的问题是代码"i = x >> 1"中">>"的含义是什么?

谢谢您的帮助.

Sam*_*Sam 7

'>>'是二元移位运算符.它将其左操作数(在您的示例中为x)的位向右移动其右侧操作数(在您的示例中为1)中指定的数字.

示例:
假设x的值为16.这是二进制的,为10000.

x = 16; //     x = 0b10000 = 16
Run Code Online (Sandbox Code Playgroud)

所以"x >> 1"的值为二进制值1000,或十进制值为8.

i = x >> 1; // i = 0b01000 =  8
Run Code Online (Sandbox Code Playgroud)

Searching for symbols on google and stack overflow is difficult without text around the symbols. Try using http://symbolhound.com/ when searching for symbols in the future.