<doc>
  <legacy_id>1525</legacy_id>
  <name>baseConvert</name>
  <type>function</type>
  <syntax>
    <example>baseConvert(<i>number</i>,<i>originalBase</i>,<i>destinationBase</i>)</example>
  </syntax>
  <library></library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
    <category>Math, Logic, &amp; Dates</category>
  </classification>
  <references>
    <function tag="URLDecode">URLDecode Function</function>
    <function tag="exp">exp Function</function>
    <function tag="format">format Function</function>
    <operator tag="bitNot">bitNot Operator</operator>
    <property tag="convertOctals">convertOctals Property</property>
  </references>
  <history>
    <introduced version="1.0">Added.</introduced>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
  </security>
  <summary>Converts a number from one base to another.</summary>
  <examples>
    <example>baseConvert(16,10,2) <code><i>-- yields 10000, which is 16 in base 2</i></code></example>
    <example>baseConvert(27,10,16) <code><i>-- yields 1B, which is 27 in base 16</i></code></example>
    <example>baseConvert("1C",16,10) <code><i>-- yields 28, the base-10 equivalent of 1C</i></code></example>
  </examples>
  <description>
    <p>Use the <b>baseConvert</b> function to provide input or output of numbers in a base other than base 10: for example, in <glossary tag="hexadecimal">hexadecimal</glossary> (base 16) or <glossary tag="binary">binary</glossary> (base 2).</p><p/><p><b>Parameters:</b></p><p>The <i>number</i> is the number to be converted, expressed in its original base. The <i>number</i> must be an <keyword tag="integer">integer</keyword> between zero and 4,294,967,295 (2^32 - 1). If the <i>number</i> includes non-digits (as, for example, a base-16 number can include letters A-F), enclose the <i>number</i> in quotes.</p><p/><p>The <i>originalBase</i> is an <keyword tag="integer">integer</keyword> between 2 and 36.</p><p/><p>The <i>destinationBase</i> is an <keyword tag="integer">integer</keyword> between 2 and 36.</p><p/><p><b>Value:</b></p><p>The <b>baseConvert</b> function <glossary tag="return">returns</glossary> a number, expressed in the <i>destinationBase</i>.</p><p/><p><b>Comments:</b></p><p>The everyday decimal number system is called "base 10" because we count from 1 to 9, and the tenth digit moves over to the tens place and is written<code> 10</code>: one group of ten, plus zero extra ones. Similarly, a number like<code> 384 </code>means one group of a hundred (10^2), plus eight groups of ten, plus four leftover ones.</p><p/><p>It is possible to write numbers in other bases. For example, suppose you want to write the number six in base 4. In base 4, we count from 1 to 3, and the fourth digit moves over to the "fours place". So the numbers from one to six, in base 4, are written "<code>1</code>,<code> 2</code>,<code> 3</code>,<code> 10</code>,<code> 11</code>,<code> 12</code>". The number<code> 12 </code>in base 4 means one group of four, plus two leftover ones. This same number is written as<code> 6 </code>in base 10.</p><p/><p>If the base is greater than 10, then digits greater than 9 are expressed as capital letters: A is the digit ten, B is the digit eleven, and so on.</p><p/><p>LiveCode always does math in base 10, so if you want to perform mathematical calculations such as addition on a number in another base, you must first convert the number to base 10, do the calculation, then convert back to the original base. Here is an example:</p><p/><p><code>  function hexSum firstAddend, secondAddend</code></p><p><code>    </code><code><i>-- adds together two hexadecimal numbers</i></code></p><p><code>    put baseConvert(firstAddend,16,10) into convertedAddend1</code></p><p><code>    put baseConvert(secondAddend,16,10) into convertedAddend2</code></p><p><code>    put convertedAddend1 + convertedAddend2 into baseTenSum</code></p><p><code/>    return baseConvert(baseTenSum,10,16)</p><p><code>  end hexSum</code></p>
  </description>
</doc>