Files
qianbian/analysis/web/hex.js

16 lines
570 B
JavaScript

function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return new Uint8Array(bytes);
}
function bytesToHex(data) {
return new Uint8Array(data).reduce(
function (memo, i) {
return memo + ("0" + i.toString(16)).slice(-2);
}, "");
}
function intToHex(intIn, bytes = 4) {
return intIn.toString(16).padStart(bytes * 2, '0');
}