Skip to content

Instantly share code, notes, and snippets.

@mkg20001
Created June 10, 2020 04:18
Show Gist options
  • Save mkg20001/3defbcb303903c7fd99c45caa3ad10d5 to your computer and use it in GitHub Desktop.
Save mkg20001/3defbcb303903c7fd99c45caa3ad10d5 to your computer and use it in GitHub Desktop.
Base Conversion Function
// 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