Friday, October 10, 2025
HomeLanguagesPHP | gmp_scan0() Function

PHP | gmp_scan0() Function

The gmp_scan0() is an inbuilt function which is used to scan “0” in a GMP number(GNU Multiple Precision : For large numbers) starting from given index which move towards most significant bits in the number.

Syntax:

gmp_scan0($num, $index)

Parameters: This function accepts two parameters as explained below:

  • $num: This parameter is a GMP number and is mandatory to be passed. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
  • $index: This parameter represents the index or position in the bitwise representation of the number $num from where we want to start the search.

Return Value: The function returns the position where we find “0” in the number.

Examples:

Input : gmp_scan0("101111101", 6)
Output : 7

Input : gmp_scan0("111001111", 2)
Output : 4

Below programs illustrate the gmp_scan0() function in PHP:

Program 1: Program to find the position of “0” bit in GMP number when numeric strings as GMP numbers are passed as arguments.




<?php
  
// PHP program to find position of "0" bit in GMP
// number passed as arguments
  
// strings as GMP numbers
$num = "10110001";
$pos = 2;
  
  
echo gmp_scan0($num, $pos) . "\n";
  
?>


Output:

6

Program 2: Program to find the position of “0” bit in GMP number when GMP numbers are passed as arguments.




<?php
// PHP program to find position of "0" bit in GMP
// number
  
//creating GMP numbers using gmp_init()
$num = gmp_init(10001111101);
$pos = 2;
  
echo gmp_scan0($num, $pos) . "\n";
  
?>


Output:

7

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS