• PHP Video Tutorials

PHP - gmp_​testbit() Function



Definition and Usage

The gmp_​testbit() function test if the bit is set for the given index.

Description

The gmp_​testbit() function checks if the bit is set for the GMP number using the gmp_setbit() function.

Syntax

gmp_testbit ( GMP $a , int $index ) : bool

Parameters

Sr.No Parameter & Description
1

a

It can a GMP resource number , a gmp object or a numeric string.

2

index

The bit to test.

Return Values

PHP gmp_testbit() function returns true if the bit is set for the index given otherwise false.

PHP Version

This function will work from PHP Version greater than 5.3.0.

Example 1

Working of gmp_testbit() −

<?php
   $a = gmp_init("5");
   var_dump(gmp_testbit($a, 1));
   echo "<br/><br/>";
   gmp_setbit($a, 1);
   var_dump(gmp_testbit($a, 1));
?>

This will produce following result −

bool(false)
bool(true)

Example 2

Working of gmp_testbit() −

<?php
   $a = gmp_init(150);
   var_dump(gmp_testbit($a, 0));
   echo "<br/><br/>";
   gmp_setbit($a, 0);
   var_dump(gmp_testbit($a, 0));
?>

This will produce following result −

bool(false)
bool(true)
php_function_reference.htm
Advertisements