function num10ToNum26(num){
let chars='abcdefghijklmnopqrstuvwxyz'
let charArr=chars.split('');
let targets=[];
while (num>0){
let yn= num%26;
targets.push(yn);
num=(num-yn)/26;
}
targets.reverse();
let target='';
for(let i=0;i<targets.length;i++){
target+=charArr[targets[i]];
}
console.log('targets:'+JSON.stringify(targets));
return target;
}
function num26TNum10(str){
let chars='abcdefghijklmnopqrstuvwxyz'
let charArr=chars.split('');
let strs=str.split('');
let total=0;
for(let i=0;i<strs.length;i++){
let num=0;
for(let j=0;j<charArr.length;j++){
if(charArr[j]===strs[i]){
num=j;
break;
}
}
let dd=1;
for(let m=0;m<strs.length-i-1;m++){
dd=dd*26;
}
total+=(num*dd);
}
return total;
}
我也做了一个计算器,也支持任意进制,上不封顶