<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>进制转换</title>
</head>
<body>
<script type="text/javascript">
// 十进制转16进制 aa 0c 13 00 00 00 00 00 00 02 04 1e bd
// aa,0f,13,00,00,00,00,00,00,02 01, 01, 00, 00,00,da
// aa 0f 13 00 00 00 00 00 00 02 04 d6 00 00 00 02
var array = [170,12,19,0,0,0,0,0,0,2,4,30,189];
console.log(array[19]);
var newArray = array.map(item=>{
return item.toString(16);
});
var result = "";
newArray.forEach(function(currentValue){
if(currentValue.length<2){
currentValue = "0"+currentValue;
}
result = result+currentValue;
});
console.log(result);
// 十六进制转十进制
var arr = ['aa','0f','13','00','00','00','00','00','00','02','01','01','00','00','00','da'];
var arr2 = arr.map(item=>{
return parseInt(item,16);
})
console.log(arr2);
</script>
</body>
</html>
网友评论