+ 1
What is this "^" sign called?
<?php function maths($num1, $num2) { echo $num1 ^ $num2; } maths(3, 6); ?>
3 Réponses
+ 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
+ 7
it's a bitwise operator
https://www.sololearn.com/learn/4074/?ref=app