0

Possible Duplicate:
Reference - What does this symbol mean in PHP?

Can someone tell me what's the << 0 for? and other more common alternatives if they exist

$newvalue += 1 << 0;
Community
  • 1
  • 1
park
  • 279
  • 1
  • 5
  • 11

2 Answers2

6

<< is the bitwise left-shift operator.
In this case is seems pretty pointless, since left-shifting 1 by 0 equals 1.

deceze
  • 471,072
  • 76
  • 664
  • 811
3

<< 0 does nothing. It is probably there to indicate that the value is some sort of flag. If it was something other than 0, than it would shift the value (1) left by x bits, where is is the value replacing 0.

ughoavgfhw
  • 39,083
  • 6
  • 98
  • 121
  • Can you give an example of what it would do if the value was something other than 0? – JakeParis Jan 04 '11 at 03:25
  • 2
    It is a moves the bits in the number over the number of times. 1 << 1 is 2, 1 << 2 is 4, 1 << 3 is 8, etc. Basically, it multiplies by 2 to the power given. – ughoavgfhw Jan 04 '11 at 03:31
  • @JMC `1 << 1` is 2, `1 << 2` is 4, etc. Make yourself familiar with [binary representation](http://en.wikipedia.org/wiki/Binary_numeral_system) of numbers, then the operator is self-explanatory. – deceze Jan 04 '11 at 03:33