No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

gmp_setbit

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

gmp_setbitSet bit

Description

gmp_setbit ( GMP $a , int $index [, bool $bit_on = TRUE ] ) : void

Sets bit index in a.

PHP: gmp_setbit - Manual Home of Manuel PHP  Contents Haut

Parameters

a

The value to modify.

Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.

index

The index of the bit to set. Index 0 represents the least significant bit.

bit_on

True to set the bit (set it to 1/on); false to clear the bit (set it to 0/off).

PHP: gmp_setbit - Manual Home of Manuel PHP  Contents Haut

Return Values

A GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later.

PHP: gmp_setbit - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 gmp_setbit() example - 0 index

<?php
$a 
gmp_init("2"); //
echo gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
gmp_setbit($a0); // 0b10 now becomes 0b11
echo gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
?>

The above example will output:

2 -> 0b10
3 -> 0b11

Example #2 gmp_setbit() example - 1 index

<?php
$a 
gmp_init("0xfd");
echo 
gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
gmp_setbit($a1); // index starts at 0
echo gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
?>

The above example will output:

253 -> 0b11111101
255 -> 0b11111111

Example #3 gmp_setbit() example - clearing a bit

<?php
$a 
gmp_init("0xff");
echo 
gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
gmp_setbit($a0false); // clear bit at index 0
echo gmp_strval($a), ' -> 0b'gmp_strval($a2), "\n";
?>

The above example will output:

255 -> 0b11111111
254 -> 0b11111110

PHP: gmp_setbit - Manual Home of Manuel PHP  Contents Haut

Notes

Note:

Unlike most of the other GMP functions, gmp_setbit() must be called with a GMP resource that already exists (using gmp_init() for example). One will not be automatically created.

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-gmp-setbit.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut