Cover Image for PHP gmp_and() Function
184 views

PHP gmp_and() Function

As of my last update in September 2021, the gmp_and() function in PHP is used to perform the bitwise AND operation between two GMP (GNU Multiple Precision) numbers. The bitwise AND operation sets each bit in the result to 1 only if the corresponding bits in both operands are 1.

Here’s the syntax of the gmp_and() function:

GMP gmp_and ( GMP $num1 , GMP $num2 )

Parameters:

  • $num1: The first GMP number.
  • $num2: The second GMP number.

Return value:

  • The result of the bitwise AND operation as a new GMP number.

Example:

$num1 = gmp_init('21');  // Binary representation: 10101
$num2 = gmp_init('10');  // Binary representation: 00101

$result = gmp_and($num1, $num2);

echo gmp_strval($result); // Output: 0 (Binary representation: 00000)

In this example, the gmp_and() function performs the bitwise AND operation between the GMP numbers 21 (binary 10101) and 10 (binary 00101), resulting in the new GMP number with the value 0 (binary 00000).

The gmp_and() function is useful for manipulating individual bits in a number or performing bitwise operations on large integers.

As with other GMP functions, ensure that the GMP extension is enabled in your PHP configuration to use this function. Additionally, please note that the availability of functions may change in newer PHP versions, so always refer to the PHP manual for the specific version you are using.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS