Skip to content

Number system conversion(进制转换)

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:

js
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("");
}

天上的神明与星辰,人间的艺术和真纯,我们所敬畏和热爱的,莫过于此。