Created
July 22, 2013 16:15
-
-
Save pdaoust/6055186 to your computer and use it in GitHub Desktop.
A simple radix(n) encoding function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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