<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.math.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.base-convert.php',
    1 => 'base_convert',
    2 => 'Convert a number between arbitrary bases',
  ),
  'up' => 
  array (
    0 => 'ref.math.php',
    1 => 'Math Functions',
  ),
  'prev' => 
  array (
    0 => 'function.atanh.php',
    1 => 'atanh',
  ),
  'next' => 
  array (
    0 => 'function.bindec.php',
    1 => 'bindec',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/math/functions/base-convert.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.base-convert" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">base_convert</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">base_convert</span> &mdash; <span class="dc-title">Convert a number between arbitrary bases</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.base-convert-description">
  <h3 class="title">Description</h3>
   <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>base_convert</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$num</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$from_base</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$to_base</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Returns a string containing <code class="parameter">num</code>
   represented in base <code class="parameter">to_base</code>.  The base in
   which <code class="parameter">num</code> is given is specified in
   <code class="parameter">from_base</code>.  Both
   <code class="parameter">from_base</code> and <code class="parameter">to_base</code>
   have to be between 2 and 36, inclusive.  Digits in numbers with a
   base higher than 10 will be represented with the letters a-z,
   with a meaning 10, b meaning 11 and z meaning 35.
   The case of the letters doesn&#039;t matter, i.e.
   <code class="parameter">num</code> is interpreted case-insensitively.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    <span class="function"><strong>base_convert()</strong></span> may lose precision on large numbers
    due to properties related to the internal <span class="type"><a href="language.types.float.php" class="type float">float</a></span> type used.
    Please see the <a href="language.types.float.php" class="link">Floating point numbers</a>
    section in the manual for more specific information and limitations.
   </p>
  </div>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.base-convert-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">num</code></dt>
     <dd>
      <p class="para">
       The number to convert. Any invalid characters in
       <code class="parameter">num</code> are silently ignored.
       As of PHP 7.4.0 supplying any invalid characters is deprecated.
      </p>
     </dd>
    
    
     <dt><code class="parameter">from_base</code></dt>
     <dd>
      <p class="para">
       The base <code class="parameter">num</code> is in
      </p>
     </dd>
    
    
     <dt><code class="parameter">to_base</code></dt>
     <dd>
      <p class="para">
       The base to convert <code class="parameter">num</code> to
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.base-convert-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <code class="parameter">num</code> converted to base <code class="parameter">to_base</code>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.base-convert-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       Passing invalid characters will now generate a deprecation notice.
       The result will still be computed as if the invalid characters did not exist.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.base-convert-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>base_convert()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$hexadecimal </span><span style="color: #007700">= </span><span style="color: #DD0000">'a37334'</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">base_convert</span><span style="color: #007700">(</span><span style="color: #0000BB">$hexadecimal</span><span style="color: #007700">, </span><span style="color: #0000BB">16</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">101000110111001100110100</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.base-convert-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.intval.php" class="function" rel="rdfs-seeAlso">intval()</a> - Get the integer value of a variable</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>