4

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

What does this line do?

$theVal = ((($theR << 8) | $theG) << 8) | $theB;

What do the << and | do?

Community
  • 1
  • 1
Subash
  • 3,128
  • 6
  • 30
  • 44

2 Answers2

4

Those are Bitwise operators that allow evaluation and manipulation of specific bits within an integer.

$a | $b Or Bits that are set in either $a or $b are set.

$a << $b Shift left Shift the bits of $a $b steps to the left (each step means "multiply by two")

$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means "divide by two")

Chris_O
  • 3,429
  • 1
  • 22
  • 28
3

The literal answer can be found by reading about Bitwise Operators.

Practically speaking, it converts 3 values for Red, Blue and Green bytes into a single 24bit RGB value.

Dancrumb
  • 26,597
  • 10
  • 74
  • 130