<script>
function utf8HexToStr(str) {
str = str.replaceAll(" ","");
console.log(str);
var arr = [];
for (var i = 0; i < str.length; i += 2) {
arr.push(parseInt(str.substring(i, i + 2), 16));
}
if (typeof arr === 'string') {
return arr;
}
var UTF = '', _arr = arr;
for (var i = 0; i < _arr.length; i++) {
var one = _arr[i].toString(2), v = one.match(/^1+?(?=0)/);
if (v && one.length == 8) {
var bytesLength = v[0].length;
var store = _arr[i].toString(2).slice(7 - bytesLength);
for (var st = 1; st < bytesLength; st++) {
store += _arr[st + i].toString(2).slice(2);
}
UTF += String.fromCharCode(parseInt(store, 2));
i += bytesLength - 1;
} else {
UTF += String.fromCharCode(_arr[i])
}
}
return UTF;
}
console.log(utf8HexToStr("73 6F 73 20 63 61 6C 6C 0D 0A"));
</script>
hex to string 16进制转字符串
最新推荐文章于 2024-07-31 04:33:20 发布