PHP Manual
Prev | Chapter 10. Operators | Next

# Bitwise Operators

Bitwise operators allow you to turn specific bits within an integer on or off.

Table 10-2. Bitwise Operators

example | name | result
--- | --- | ---
$a & $b | And | Bits that are set in both $a and $b are set.
$a | $b | Or | Bits that are set in either $a or $b are set.
$a ^ $b | Xor | Bits that are set in $a or $b but not both are set.
~ $a | Not | Bits that are set in $a are not set, and vice versa.
$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")

Prev | Home | Next
Assignment Operators | Up | Comparison Operators