Created
June 10, 2020 04:18
-
-
Save mkg20001/3defbcb303903c7fd99c45caa3ad10d5 to your computer and use it in GitHub Desktop.
Base Conversion Function
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
// ib = input base | |
// ob = output base | |
// n = number to convert | |
// r = leftover from division | |
// o = output number | |
// x = exponent (base ^ position) | |
function roxn(ib, ob, n) { | |
let x = 1 | |
let o = 0 | |
while(n) { | |
let r = n % ib | |
o += r * x | |
x *= ob | |
n = (n - r) / ib | |
} | |
return o | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment