Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For what it's worth, here's a modification of the solution to convert to any base up to 64:</p> <pre><code>// Convert decimal into a base between 2 and 64 var decToBase = function() { var decToBaseMap = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'Y', 'Z', '+', '/']; return function(number, base) { if (base &lt; 2 || base &gt; 64) { return "#base should be between 2 and 64#"; } var negative = ''; if (number &lt; 0) { negative = '-'; } number = number.toString().split('.'); var integer = Math.abs(number[0]); var fraction = number[1]; var result = ''; do { result = decToBaseMap[integer % base] + result; integer = parseInt(integer / base, 10); } while (integer &gt; 0); if (fraction) { var decimalPlaces = fraction.toString().length; result += '.'; fraction = parseFloat('.' + fraction); var x = 0; do { x++; var res = (fraction * base).toString().split('.'); result = result + decToBaseMap[res[0]]; if (res[1]) { fraction = parseFloat('.' + res[1]); } else { break; } } while (x &lt; decimalPlaces); } return negative + result; }; }(); alert(decToBase(2011, 64)); // displays "VR" </code></pre> <p>You can play with it here: <a href="http://jsfiddle.net/kaicarver/d3Zn2/" rel="nofollow">http://jsfiddle.net/kaicarver/d3Zn2/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload