/** * 16进制转换为字符串 * @param hex * @returns {*} */ function hexToString(hex) { var tmp = ‘‘; if (hex.length % 2 == 0 ) { for (var i = 0; i < hex.length; i += 2) { tmp += ‘%‘ + hex.charAt(i) + hex.charAt(i + 1); } } return decodeURIComponent(tmp); } /** * 字符串转16进制 * @param str * @returns {string} */ function stringToHex(str) { var hex = ""; for (var i = 0; i < str.length; i++) { hex += str.charCodeAt(i).toString(16); } return hex; }
时间: 2024-10-27 14:20:15