十进制转化为其他进制123456789101112function binary(num, base = 2) { const stack = [] const digits = '0123456789ABCDEF' while (num > base - 1) { stack.push(digits[num % base]) num = ~~(num / 2) } stack.push(digits[num]) return stack.reverse().join('')}console.log(binary(10)) // '1010'