Skip to content

Instantly share code, notes, and snippets.

@No-Eul
Created September 18, 2024 06:22
Show Gist options
  • Save No-Eul/7a34cdf8312553dadb8ca228c6b89ab7 to your computer and use it in GitHub Desktop.
Save No-Eul/7a34cdf8312553dadb8ca228c6b89ab7 to your computer and use it in GitHub Desktop.
function floorMod(a, b) {
return a - b * Math.floor(a / b);
}
function toRadix(decimal, base) {
let array = [];
do array.unshift(floorMod(decimal, base));
while ((decimal = Math.floor(decimal / base)) !== 0);
return array;
}
function toDecimal(radix, base) {
return radix.reverse().reduce((acc, cur, i, arr) => acc + cur * base ** i);
}
console.log(toRadix(-15, -2))
console.log(toDecimal([ 4, 3, 7 ], -10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment