VOOZH about

URL: https://www.geeksforgeeks.org/php/php-gmp_xor-function/

⇱ PHP | gmp_xor() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP | gmp_xor() Function

Last Updated : 11 Jul, 2025
The gmp_xor() is an in-built function in PHP which is used to calculate the XOR of 2 GMP numbers (GNU Multiple Precision : For large numbers). Syntax:
gmp_xor( $num1, $num2 )
Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters shown in the above syntax. These parameters can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. Return Value: This function returns a positive GMP number which is the XOR of $num1 and $num2. Examples:
Input : $num1 = "3" $num2 = "5"
Output : 6

Input : $num1 = 1 $num2 = 1
Output : 0 
Below programs illustrate the gmp_xor() function: Program 1: The program calculates the XOR of two numbers when numeric strings as GMP numbers are passed as arguments. Output:
6
Program 2: The program calculates the XOR of two numbers when GMP numbers are passed as arguments. Output:
1011110111
Reference: https://www.php.net/manual/en/function.gmp-xor.php
Comment
Article Tags: