<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.gmp-setbit" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>gmp_setbit</refname>
  <refpurpose>Set bit</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>void</type><methodname>gmp_setbit</methodname>
   <methodparam><type>GMP</type><parameter>num</parameter></methodparam>
   <methodparam><type>int</type><parameter>index</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>value</parameter><initializer>&true;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Sets bit <parameter>index</parameter> in <parameter>num</parameter>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>num</parameter></term>
     <listitem>
      <para>
       A <classname>GMP</classname> object.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>index</parameter></term>
     <listitem>
      <para>
       The index of the bit to set.  Index 0 represents the least significant bit.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>value</parameter></term>
     <listitem>
      <para>
       True to set the bit (set it to 1/on); false to clear the bit (set it to 0/off).
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &gmp.return;
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>gmp_setbit</function> example - 0 index</title>
    <programlisting role="php">
<![CDATA[
<?php
$a = gmp_init("2"); //
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
gmp_setbit($a, 0); // 0b10 now becomes 0b11
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
2 -> 0b10
3 -> 0b11
]]>
    </screen>
   </example>

   <example>
    <title><function>gmp_setbit</function> example - 1 index</title>
    <programlisting role="php">
<![CDATA[
<?php
$a = gmp_init("0xfd");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
gmp_setbit($a, 1); // index starts at 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
253 -> 0b11111101
255 -> 0b11111111
]]>
    </screen>
   </example>

   <example>
    <title><function>gmp_setbit</function> example - clearing a bit</title>
    <programlisting role="php">
<![CDATA[
<?php
$a = gmp_init("0xff");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
gmp_setbit($a, 0, false); // clear bit at index 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n";
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
255 -> 0b11111111
254 -> 0b11111110
]]>
    </screen>
   </example>

  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    Unlike most of the other GMP functions, <function>gmp_setbit</function>
    must be called with a GMP object that already exists (using
    <function>gmp_init</function> for example). One will not be
    automatically created.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>gmp_clrbit</function></member>
    <member><function>gmp_testbit</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
