What is this "^" sign called? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is this "^" sign called?

<?php function maths($num1, $num2) { echo $num1 ^ $num2; } maths(3, 6); ?>

2nd Jan 2019, 11:57 AM
Jignesh Patel
Jignesh Patel - avatar
3 Answers
+ 8
That is the xor bitwise operator and work with 2 operand at bit level. In binary field (where exist only two value true and false tagged respectively like 1 and 0) its applied to two binary operands and return true (1) if only one is true else it return false (in a simpler way you can considerate it like returning true if the binary values are differents else it return false)... Table: 0 ^ 0 = 0 1 ^ 0 = 1 1 ^ 1 = 0 0 ^ 1 = 1 Applied to not-binary values (like integers) it return an integer formed by appling it to all bits of integers (taked in same position) example: 3 ^ 6= 0011 ^ 0110 = 0101 = 5 Why 3 (decimal) = 0 0 1 1 ^ 6 (decimal) = 0 1 1 0 --------------------------- 0 1 0 1 = 5 (decimal) I used only 4 bits for easy read
2nd Jan 2019, 12:15 PM
KrOW
KrOW - avatar
2nd Jan 2019, 12:17 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar