비트 연산자

비트 연산자는 특정 비트를 정수로 on이나 off로 전환하도록 한다. 좌측과 우측 인자가 문자열이면, 비트 연산자는 이 문자열안의 문자에 대해 계산하게 된다.

<?php
    
echo 12 ^ 9; // Outputs '5'

    
echo "12" ^ "9"; // Outputs the Backspace character (ascii 8)
                     // ('1' (ascii 49)) ^ ('9' (ascii 57)) = #8

    
echo "hallo" ^ "hello"; // Outputs the ascii values #0 #4 #0 #0 #0
                            // 'a' ^ 'e' = #4
?>

표 10-3. 비트 연산자

ExampleNameResult
$a & $bAndBits that are set in both $a and $b are set.
$a | $bOrBits that are set in either $a or $b are set.
$a ^ $bXor Bits that are set in $a or $b but not both are set.
~ $aNot Bits that are set in $a are not set, and vice versa.
$a << $bShift left Shift the bits of $a $b steps to the left (each step means "multiply by two")
$a >> $bShift right Shift the bits of $a $b steps to the right (each step means "divide by two")