//十进制转十六进制
function HexNum(num){
if(num < 10)
return num;
var ch = ['A','B','C','D','E','F'];
if(!ch[num - 10]){
//超过范围,可能是中文等数字
throw Error(‘超出范围’);
}
return ch[num - 10];
}
function Otc2Hex(num){
var hex = [];
while(num != 0){
hex.push(HexNum(num%16));
num /= 16;
num = parseInt(num);
}
return hex.reverse().join('');
}
console.log(Otc2Hex(65036));
网友评论