Please explain one instruction

Feb 15, 2016 at 11:36pm
What does the following statement mean? What I need to know is, for example, what (1<<29) mean (and (1<<29)+5, etc).

 
  int testnums [] = {0, 1<<29 , (1<<29) + 5 , 50, (1<<30) + 5, (1<<30) - 500};
Feb 15, 2016 at 11:45pm
Basically, it's a very very large number. The << operator is the left shift operator, which performs binary operations.

For example, let's say you have a number 0b0001 (binary). The left shift operator moves everything a certain number of steps to the left:
0b0001 << 1 = 0b0010 = 2
0b0001 << 2 = 0b0100 = 4
0b0001 << 3 = 0b1000 = 8


Now, your code is exactly the same, but shifting to a very large number. Also, it should be long rather than int, because ints won't necessarily be 32 bits long. If, for example, it's 16 bits long, all the bits will be shifted away and you'll be left with 0.
Last edited on Feb 15, 2016 at 11:45pm
Topic archived. No new replies allowed.