Created
September 14, 2014 13:34
-
-
Save z-------------/991e58edf5ff9f4e8849 to your computer and use it in GitHub Desktop.
Convert integers between any two bases
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
| 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