Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created September 14, 2014 13:34
Show Gist options
  • Save z-------------/991e58edf5ff9f4e8849 to your computer and use it in GitHub Desktop.
Save z-------------/991e58edf5ff9f4e8849 to your computer and use it in GitHub Desktop.
Convert integers between any two bases
function base(n, from, to) {
if (typeof n === "number") {
n = n.toString();
}
var baseTen = parseInt(n, from);
return baseTen.toString(to);
}
/*
base("f", 16, 10)
--> 15
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment