Created
September 20, 2011 16:23
-
-
Save joshje/1229568 to your computer and use it in GitHub Desktop.
Base60 Converter
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>Base60 Converter</title> | |
</head> | |
<body> | |
<p><label for="n">Number</label><input id="n"> → <label for="s">Base 60</label><input id="s"></p> | |
<script> | |
ni = document.getElementById('n'); | |
si = document.getElementById('s'); | |
n.onkeyup = function() { | |
si.value = num_to_sxg(this.value); | |
} | |
s.onkeyup = function() { | |
ni.value = sxg_to_num(this.value); | |
} | |
function num_to_sxg(n) { | |
s = ""; | |
m = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz"; | |
if (n===undefined || n===0) { return 0; } | |
while (n>0) { | |
d = n % 60; | |
s = m[d]+s; | |
n = (n-d)/60; | |
} | |
return s | |
} | |
function sxg_to_num(s) { | |
n = 0; | |
j = s.length; | |
for (i=0;i<j;i++) { | |
c = s.charCodeAt(i); | |
if (c>=48 && c<=57) { c=c-48; } | |
else if (c>=65 && c<=72) { c-=55; } | |
else if (c==73 || c==108) { c=1; } | |
else if (c>=74 && c<=78) { c-=56; } | |
else if (c==79) { c=0; } | |
else if (c>=80 && c<=90) { c-=57; } | |
else if (c==95) { c=34; } | |
else if (c>=97 && c<=107) { c-=62; } | |
else if (c>=109 && c<=122) { c-=63; } | |
else { c = 0; } | |
n = 60*n + c; | |
} | |
return n; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A Javascript converter using http://tantek.pbworks.com/w/page/19402946/NewBase60