Skip to content

Instantly share code, notes, and snippets.

@pdaoust
Created July 22, 2013 16:15
Show Gist options
  • Save pdaoust/6055186 to your computer and use it in GitHub Desktop.
Save pdaoust/6055186 to your computer and use it in GitHub Desktop.
A simple radix(n) encoding function
var toRadix = (function () {
var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
return function(N, radix) {
var HexN = "", Q = Math.floor(Math.abs(N)), R;
while (true) {
R = Q % radix;
HexN = chars.charAt(R) + HexN;
Q = (Q - R) / radix;
if (Q == 0) break;
}
return ((N < 0) ? "-" + HexN : HexN);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment