PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<赋值运算符比较运算符>
Last updated: Mon, 16 Jul 2012

位运算符

位运算符允许对整型数中指定的位进行置位。如果左右参数都是字符串,则位运算符将操作这个字符串中的字符。

<?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
?>

表格 15-3. 位运算符

例子名称结果
$a & $bAnd(按位与)将在 $a 和 $b 中都为 1 的位设为 1。
$a | $bOr(按位或)将在 $a 或者 $b 中为 1 的位设为 1。
$a ^ $bXor(按位异或)将在 $a 和 $b 中不同的位设为 1。
~ $aNot(按位非)将 $a 中为 0 的位设为 1,反之亦然。
$a << $bShift left(左移)将 $a 中的位向左移动 $b 次(每一次移动都表示“乘以 2”)。
$a >> $bShift right(右移)将 $a 中的位向右移动 $b 次(每一次移动都表示“除以 2”)。



<赋值运算符比较运算符>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST