What is the gmp_xor() function in PHP?
Overview
The gmp_xor() function in PHP is used to find the bitwise XOR of the given two numbers.
Note: You can learn more about the bitwise XOR operator here.
Syntax
gmp_xor(GMP|int|string $num1, GMP|int|string $num2): GMP
Parameters
num1: This is a GMP object, integer, or a string.num2: This is a GMP object, integer, or a string.
Return value
The method returns the bitwise XOR of num1 and num2.
Code
<?php$num1 = gmp_init(5);$num2 = gmp_init(3);$xor = gmp_xor($num1, $num2);print "5 ^ 3 = ".$xor;?>
Explanation
- Line 2: We define
num1. - Line 3: We define
num2. - Line 4: We calculate the XOR of
num1andnum2using thegmp_xor()method. - Line 5: We print the bitwise XOR result.