js、JavaScript进制转换

 

function baseConverter(decNumber, base) {
  var remStack = new Stack(),
    rem,
    baseString = '',
    digits = '0123456789ABCDEF'; //{6} 
  while (decNumber > 0) {
    rem = Math.floor(decNumber % base);
    remStack.push(rem);
    decNumber = Math.floor(decNumber / base);
  }
  while (!remStack.isEmpty()) {
    baseString += digits[remStack.pop()]; //{7} 
  }
  return baseString;
}

 

posted @ 2024-01-03 10:12  LaLaLa_heng  阅读(4)  评论(0编辑  收藏  举报