十进制转16进制内的js方法
let num = 127 const trans = (num,x)=>{ let r = [] let t = { 10:'A', 11:'B', 12:'C', 13:'D', 14:'E', 15:'F' } while(num>=x){ r.push(num%x) num = num/x|0 } r.push(num%x) let str = '' for(let i=0;i<r.length;i++){ if(+r[i]>9){ str = t[r[i]] + str }else{ str = r[i] + str } } return str } let res = trans(num,9) console.log(res)