Created
November 23, 2017 07:07
-
-
Save alexcambose/6ded01e770be8c572fcb67337efe221c to your computer and use it in GitHub Desktop.
Convert any number to any base
This file contains 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
const numToBase = (number, base) => { | |
let newNum = 0; | |
let p10 = 1; | |
while(number) { | |
newNum = newNum + (number % base) * p10; | |
p10 *= 10; | |
number = Math.floor(number / base); | |
} | |
return newNum; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment