Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bitwise Operators

Bitwise operators evaluate specific bits within an integer.

Bitwise operators are convenient to handle bit fields.

  • &, &=: ampersand operator, and
  • |, |=: pipe operator, or
  • ^, ^=: caret operator, xor

All these operators have a short assignation version, as shown above.

These operators differ from logical operators, which convert the value to boolean before manipulation.

<?php

    $a = 3;  // binary : 11
    $b = 7;  // binary : 111
    
    print $a & $b; // 3; binary : 11

?>

Documentation

See Also