-2
tempValue = input2[0] << 8;

I can't figure out what the << does in this line of code. What is this used for?

squiguy
  • 32,370
  • 6
  • 56
  • 63
Tyler McAtee
  • 300
  • 2
  • 12
  • If you have no book or tutorial available where you can look up fundamental language syntax, I'd say you are in quite a bit of trouble. – Lundin Mar 19 '13 at 07:28
  • If you don't know operators, you cannot know the precedence, thus you cannot undestatn anything. You must start from the beginning, not by looking at some "complicated" code. – V-X Mar 19 '13 at 10:05

2 Answers2

4

It assigns tempValue the value in input2[0] shifted to the left by 8 bits.

Here is a link about bit shifting in C: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/bitshift.html

squiguy
  • 32,370
  • 6
  • 56
  • 63
  • Alright!! That was exactly my answer. For future reference do you have any idea how I could search for something like that on google? – Tyler McAtee Mar 19 '13 at 05:33
  • @KevinMcAtee I knew what it was called from experience. I suggest looking at a C reference book for operators and their names. I suppose Google doesn't know what `<<` means. In a nutshell, try a book first :). – squiguy Mar 19 '13 at 05:35
  • @KevinMcAtee: Search for “C operators”. – Eric Postpischil Mar 19 '13 at 10:50
0

You can google Bitwise Operation for many information.

In your case, input2[0] being Left shift(<<) for 8 bits, which is * (2^8).

So, equivalent tempValue = input2[0] * (2^8) ;

moeCake
  • 512
  • 4
  • 15