Hi,
I am trying to work some algo before i proceed any further to my final 4 projects, i came across an algo to generate decimal to any base , now i understand all the parts but the one here -
digits = '0123456789ABCDEF';
and this one -
baseString += digits[remStack.pop()];
I get results like - 187F9 for some thing like -
console.log(baseConverter(100345, 16));
Can you please explain this as to how the code is picking alphabets here … below is full code -Thanks
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}
console.log(baseString);
}
return baseString;
console.log(baseString);
}
console.log(baseConverter(100345, 16));