If you want to convert a number from decimal system to binary system, you can do conversion like the picture shown below:
Corresponding code is like below:
function convertNum (originNum, base) { let quotient = originNum let remainer let arr = [] while (quotient !== 0) { remainer = quotient % base // 取余 quotient = Math.floor(quotient / base) // 取商 arr.unshift(remainer) } return arr.join('') }