-2

Before tellimg me to google, please note that Google will not me search "<<" characters.

I have found the following:

data is a byte array.

int ResultChannel = data[1] + (data[2] << 8)

How does the << work?

John V
  • 4,855
  • 15
  • 39
  • 63

3 Answers3

6

Shift Left.

In C-inspired languages, the left and right shift operators are "<<" and ">>", respectively. The number of places to shift is given as the second argument to the shift operators. For example,

x = y << 2;

assigns x the result of shifting y to the left by two bits.

Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
2

<< is a left shift operator

The left-shift operator (<<) shifts its first operand left by the number of bits specified by its second operand. The type of the second operand must be an int or a type that has a predefined implicit numeric conversion to 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);
}
VladL
  • 12,769
  • 10
  • 63
  • 83
2

It a bit shift operator.

It shifts the bits to the left.

For example: the 5 << 3 returns a value that is 5 shifted three placed to the left. Five in binary is:

00000101

And if you shift that three places to the left you get:

00101000

Which is 40.

antonijn
  • 5,702
  • 2
  • 26
  • 33