添加了简单的16bit PCM数据采样i但转换功能 1. 添加页面跳转:html\uac_pcm_data_convert.html 2. 添加hex_to_int的带符号转换方法 end of segment 🔧 web(switch): add web pages switch feature 添加了页面跳转的框架 1. 添加页面跳转功能 2. 添加主页相关的内容以及欢迎页面 end of segment ✨ utools(plugin): add utools plugin support 添加了utools的插件功能 1. 添加插件配置 2. 添加插件的图标 end of segment
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
function hex2int(hexStr) {
|
||
let twoStr = parseInt(hexStr, 16).toString(2); // 将十六转十进制,再转2进制
|
||
let bitNum = hexStr.length * 4; // 1个字节 = 8bit ,0xff 一个 "f"就是4位
|
||
if (twoStr.length < bitNum) {
|
||
while (twoStr.length < bitNum) {
|
||
twoStr = "0" + twoStr;
|
||
}
|
||
}
|
||
if (twoStr.substring(0, 1) == "0") {
|
||
// 正数
|
||
twoStr = parseInt(twoStr, 2); // 二进制转十进制
|
||
return twoStr;
|
||
} else {
|
||
// 负数
|
||
let twoStr_unsign = "";
|
||
|
||
// console.log("hex2int--->" + parseInt(twoStr, 2));
|
||
twoStr = parseInt(twoStr, 2) - 1; // 补码:(负数)反码+1,符号位不变;相对十进制来说也是 +1,但这里是负数,+1就是绝对值数据-1
|
||
// console.log("hex2int--->" + twoStr);
|
||
|
||
twoStr = twoStr.toString(2);
|
||
twoStr_unsign = twoStr.substring(1, bitNum); // 舍弃首位(符号位)
|
||
// 去除首字符,将0转为1,将1转为0 反码
|
||
twoStr_unsign = twoStr_unsign.replace(/0/g, "z");
|
||
twoStr_unsign = twoStr_unsign.replace(/1/g, "0");
|
||
twoStr_unsign = twoStr_unsign.replace(/z/g, "1");
|
||
|
||
// console.log("hex2int--->" + twoStr_unsign);
|
||
// console.log("hex2int--->" + (-twoStr_unsign));
|
||
twoStr = parseInt(-twoStr_unsign, 2);
|
||
return twoStr;
|
||
}
|
||
}
|