2013-03-03 109 views
-2

在告诉我谷歌之前,请注意Google不会搜索“< <”字符。<<做什么?

我发现以下内容:

data是一个字节数组。

INT ResultChannel =数据[1] +(数据[2] < < 8)

如何进行< <工作?

+0

其实,[http://msdn.microsoft。 com/en-us/library/a1sway8w.aspx](http://msdn.microsoft.com/en-us/library/a1sway8w.aspx) – 2013-03-03 14:03:08

+0

你甚至试过谷歌? – antonijn 2013-03-03 14:04:32

+0

你有没有试过google <<字符?告诉我,如果你有它的运气... – user970696 2013-03-03 14:05:00

回答

6

向左移。

在C风格的语言,左,右移位运算符是 “< <” 和 “>>”,分别。要转移的位置的数目以 作为转移运算符的第二个参数给出。例如,

x = y << 2; 

指定x将y向左移两位的结果。

+1

不合逻辑,它是按位。 – Hauleth 2013-03-03 14:02:57

+2

@ŁukaszNiemier有两种班次,算术和逻辑。什么是非按位移? – axiom 2013-03-03 14:05:38

2

< <是left shift operator

左移操作(< <)移位由 数由它的第二操作数指定的位的左其第一个操作数。第二个 操作数的类型必须是一个int或具有预定义的隐式 数字转换为int的类型。

static void Main() 
{ 
    int i = 1; 
    long lg = 1; 
    // Shift i one bit to the left. The result is 2. 
    Console.WriteLine("0x{0:x}", i << 1); 
    // In binary, 33 is 100001. Because the value of the five low-order 
    // bits is 1, the result of the shift is again 2. 
    Console.WriteLine("0x{0:x}", i << 33); 
    // Because the type of lg is long, the shift is the value of the six 
    // low-order bits. In this example, the shift is 33, and the value of 
    // lg is shifted 33 bits to the left. 
    //  In binary:  10 0000 0000 0000 0000 0000 0000 0000 0000 
    //  In hexadecimal: 2 0 0 0 0 0 0 0 0 
    Console.WriteLine("0x{0:x}", lg << 33); 
} 
2

它是一个位移运算符。

它将位移动到左边。

例如:5 < < 3返回值为5的三位置于左侧。五二进制是:

00000101 

如果你移动你得到三个地方向左:

00101000 

这是40