PHP - gmp_​scan1() 函式



定義和用法

gmp_​scan1() 函式掃描給定數字中的 1。

描述

gmp_​scan1() 從給定的起始位置掃描 GMP 數字中的 1。找到第一個設定位時停止。

語法

gmp_scan1 ( GMP $a , int $start ) : int

引數

序號 引數及描述
1

a

將被掃描的 GMP 數字。

2

start

掃描將從哪裡開始的起始位置。

返回值

PHP gmp_scan1() 函式返回找到的位的位 置或索引的整數值。如果未設定任何位,則返回 -1。

PHP 版本

此函式在高於 5.0.0 的 PHP 版本中有效。

示例 1

gmp_scan1() 的工作原理 -

<?php
   $num = gmp_init("101110000111", 2);
   $pos = gmp_scan1($num, 4);
   echo "The position of 1 is :".$pos;
?>

這將產生以下結果 -

The position of 1 is :7

示例 2

gmp_scan0() 的工作原理 -

<?php
   $num = gmp_init("0000111", 2);
   $pos = gmp_scan1($num, 4);
   echo "The position of 1 is :".$pos;
?>

這將產生以下結果 -

The position of 1 is :-1
php_function_reference.htm
廣告