Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Bitwise XOR (^)

Find the positions where two masks differ in bit value.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$value ^ $operand

Find the positions where two masks differ in bit value. Comparing a mask with itself produces zero.

A mask works on individual bits of integers. When both operands are strings, PHP operates on their bytes and returns a string. A result bit is 1 when exactly one corresponding input bit is 1.

Evaluation

  • 12 ^ 10 → 6
  • 12 ^ 0 → 12
  • 7 ^ 7 → 0

Examples

<?php
echo json_encode(12 ^ 10), PHP_EOL;

echo json_encode(12 ^ 0), PHP_EOL;

echo json_encode(7 ^ 7), PHP_EOL;

Result

6
12
0

Sources