PHP operator

tunglam
tunglam used Ask the Experts™
on
I'm reading an ebook, it mention about those operators:
^=, &=, |=, <<=, >>=

Can anyone tell me what they are?
Thank in advanced
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
Those are bitwise operators

$a &= $b is the same as $a = $a & $b (bitwise and)
$a |= $b is the same as $a = $a | $b (bitwise or)

$a <<= 2 is the same as $a = $a << 2 (leftshifting bits)

(leftshifting 2 bits is the same as multiplying by 4, 3 bits is times 8, 4 bits, times 16, etc).

-r-

Author

Commented:
Can you what is bitwise operators?
What are they for? And give me some example? Thank you!
Top Expert 2006
Commented:
Bitwise operators work on binairy forms of data (the zero's and one's.)

So 2 & 3 equals in binairy code 0010 && 0011 => 0010 (only the second one from the right is in both binairy

0101 << 1 is the same as putting all zero's and one's one position to the left: 1010
0101 << 3: 1000
0101 >> 1: (shift to right) 0010
0101 >> 3: 0001

See also: http://nl3.php.net/manual/en/language.operators.bitwise.php

-r-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial