Skip to content

Instantly share code, notes, and snippets.

@alexcambose
Created November 23, 2017 07:07
Show Gist options
  • Save alexcambose/6ded01e770be8c572fcb67337efe221c to your computer and use it in GitHub Desktop.
Save alexcambose/6ded01e770be8c572fcb67337efe221c to your computer and use it in GitHub Desktop.
Convert any number to any base
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