Ads verification

2014-02-05

PHP ビット演算子のメモ




いつも php.net の日本語で混乱するので自分の日本語で表現しなおしてみた。

演算子 名称 説明
& ビット積 共通して立っているフラグのみ立てる。共通していない場合は折る。
| ビット和 どちらかのフラグが立っていれば立てる。どちらも立っていなければ立てないまま。
^ 排他的論理和 片方だけ立っているフラグを立てる。共通して立っているフラグは折る。


ふと思い立って英語版 php.net を見てみると、英語のほうがわかりやすかった。

Bitwise Operators
Example Name Result
$a & $b And Bits that are set in both $a and $b are set.
$a | $b Or (inclusive or) Bits that are set in either $a or $b are set.
$a ^ $b Xor (exclusive or)
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")