What does ^ mean in PHP?

I came across this line of code in an application I am revising:

substr($sometext1 ^ $sometext2, 0, 512);

What does the ^ mean?


It's a bitwise operator.

Example:

"hallo" ^ "hello"

It outputs the ASCII values #0 #4 #0 #0 #0 ( 'a' ^ 'e' = #4 ).


^ is the bitwise exclusive OR operator. For each bit in a value, it looks to see if that bit is the same in the other value; if it is the same, a 0 is output in its place, otherwise a 1 is output. For example:

  00001111
^ 01010101
  --------
  01011010

XOR (exclusive OR):

$a ^ $b means bits that are set in $a or $b, but not both, are set.

链接地址: http://www.djcxy.com/p/1776.html

上一篇: >>在PHP中意味着什么?

下一篇: ^在PHP中意味着什么?