PHP - gmp_and() 函式



定義和用法

gmp_and() 函式返回兩個數字的按位與比較結果。

描述

gmp_and() 計算兩個給定數字的按位與。

語法

gmp_and ( GMP $num1 , GMP $num2 ) : GMP

引數

序號 引數及描述
1

num1

可以是 GMP 資源數字、gmp 物件或數字字串。

2

num2

可以是 GMP 資源數字、gmp 物件或數字字串。

返回值

PHP gmp_and() 函式返回一個由按位比較生成的 GMP 數字。

PHP 版本

此函式適用於 PHP 5.0.0 及更高版本。

示例 1

gmp_and 的工作原理 -

<?php
   $num1 = '4';
   $num2 = '8';
   $num3 = gmp_and($num1, $num2);
   echo "The BITWISE AND of 4 and 8 is :".$num3;

   echo "<br/><br/>";

   $num4 = '12';
   $num5 = '25';
   $num6 = gmp_and($num4, $num5);
   echo "The BITWISE AND 12 and 15 is :".$num6;
?>

這將產生以下結果 -

The BITWISE AND of 4 and 8 is :0
The BITWISE AND 12 and 15 is :8

示例 2

使用 GMP 數字 -

<?php
   $num1 = gmp_init(4);
   $num2 = gmp_init(8);
   $num3 = gmp_and($num1, $num2);
   echo "The BITWISE AND of 4 and 8 is :".$num3;

   echo "<br/><br/>";

   $num4 = gmp_init(12);
   $num5 = gmp_init(25);
   $num6 = gmp_and($num4, $num5);
   echo "The BITWISE AND 12 and 15 is :".$num6;
?>

這將產生以下結果 -

The BITWISE AND of 4 and 8 is :0
The BITWISE AND 12 and 15 is :8
php_function_reference.htm
廣告