• PHP Video Tutorials

PHP - gmp_​scan1() Function



Definition and Usage

The gmp_​scan1() function scans the 1's in the given number.

Description

The gmp_​scan1() scans the GMP number from the given start position for 1.It will stop when it gets first set bit.

Syntax

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

Parameters

Sr.No Parameter & Description
1

a

GMP number that will be scanned.

2

start

The starting position from where the scan will begin.

Return Values

PHP gmp_scan1() function returns an integer value for the the position or index of the bit found. If it does not set a set bit, it will return -1.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_scan1() −

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

This will produce following result −

The position of 1 is :7

Example 2

Working of gmp_scan0() −

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

This will produce following result −

The position of 1 is :-1
php_function_reference.htm
Advertisements