Fastest way to convert a number to radix 64 in JavaScript?
<p>In JavaScript you can convert a number to a string representation with a specific <a href="http://en.wikipedia.org/wiki/Radix" rel="nofollow">radix</a> as follows:</p>

<pre><code>(12345).toString(36) // "9ix"
</code></pre>

<p>...and you can convert it back to a regular number like this:</p>

<pre><code>parseInt("9ix", 36) // 12345
</code></pre>

<p>36 is the highest radix you can specify. It apparently uses the characters <code>0-9</code> and <code>a-z</code> for the digits (36 total).</p>

<p>My question: what's the fastest way to convert a number to a base 64 representation (for example, using <code>A-Z</code>, and <code>-</code> and <code>_</code> for the extra 28 digits)?</p>

<hr>

<p><strong>Update</strong>: Four people have posted responses saying this question is duplicated, or that I'm looking for Base64. I'm not.</p>

<p>"<a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow">Base64</a>" is a way of encoding binary data in a simple ASCII character set, to make it safe for transfer over networks etc. (so that text-only systems won't garble the binary). </p>

<p>That's not what I'm asking about. I'm asking about converting <strong>numbers</strong> to a radix 64 string representation. (JavaScript's <code>toString(radix)</code> does this automatically for any radix up to 36; I need a custom function to get radix 64.)</p>

<hr>

<p><strong>Update 2</strong>: Here are some input &amp; output examples...</p>

<pre><code>0   → "0"
1   → "1"
9   → "9"
10  → "a"
35  → "z"
61  → "Z"
62  → "-"
63  → "_"
64  → "10"
65  → "11"
128 → "20"
etc.
</code></pre>
