# Can any one please explain this algo last part[Solved]

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));
``````

Maybe this helps:
http://www.purplemath.com/modules/base_why.htm

@BenGitter - Thanks,I am able to understand the mod picking up values like 8,15,7 etc here but what is happening at this line - `baseString += digits[remStack.pop()];` ?

So say for mod giving back a value of 15 what is happening here is the 15th index getting picked up here which corresponds to “F” …kindly guide

``````var remStack = [1, 14, 12];
var baseString = '' ;
var digits =  '0123456789ABCDEF';

baseString += digits[remStack.pop()];
console.log(baseString);        // "C"
``````
1. `remStack.pop()` returns the last element in `remStack` which is `12`.
2. `digits` is `"C"`
3. This is added (`+=`) to baseString
1 Like

Oh i get it now, thank you so much …