Tutorialspoint.dev

PHP | gmp_or() Function

The gmp_or() is an inbuilt function in PHP which is used to calculate the bitwise OR of two GMP numbers(GNU Multiple Precision : For large numbers).

Syntax:

gmp_or($num1, $num2)

Parameters: This function accepts two GMP numbers, $num1, $num2 as mandatory parameters as shown in the above syntax. These parameters can be GMP objects in PHP version 5.6 and later, or we are also allowed to pass numeric strings such that it is possible to convert those strings to numbers.

Return Value: This function returns a GMP number which is the bitwise OR of the GMP numbers passed to it as parameters.

Examples:



Input : gmp_or("4", "2")
Output : 6

Input : gmp_or("9", "10")
Output : 11

Below programs illustrate the gmp_or() function in PHP:

Program 1: Program to calculate the bitwise OR of GMP numbers when numeric strings as GMP numbers are passed as arguments.

<?php
// PHP program to calculate the bitwise OR
//  GMP numbers passed as arguments 
  
// strings as GMP numbers 
$num1 = "10";
$num2 = "9";
  
// calculate the bitwise OR of $num1 and $num2
$res = gmp_or($num1, $num2);
  
echo $res;
  
?>

Output:

11

Program 2: Program to calculate the bitwise OR of GMP numbers when GMP numbers are passed as arguments.

<?php
// PHP program to calculate the bitwise OR
//  GMP numbers passed as arguments 
  
// creating GMP numbers using gmp_init()
$num1 = gmp_init(4);
$num2 = gmp_init(2);
  
// calculate the bitwise OR of $num1 and $num2
$res = gmp_or($num1, $num2);
  
echo $res;
  
?>

Output:

6

Reference:
http://php.net/manual/en/function.gmp-or.php



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter