{"id":127632,"date":"2018-11-17T08:28:45","date_gmt":"2018-11-17T00:28:45","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=127632"},"modified":"2018-11-12T09:31:17","modified_gmt":"2018-11-12T01:31:17","slug":"nodejs-btye","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nodejs-btye.html","title":{"rendered":"nodejs\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e0ebtye\u578b\u6570\u636e\u76f8\u4e92\u8f6c\u6362"},"content":{"rendered":"
byte\u578b\u8f6c\u6362\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32<\/p>\n
\r\n\/**\r\n * byte\u578b\u8f6c\u6362\u5341\u516d\u8fdb\u5236\r\n * @param b\r\n * @returns {string}\r\n * @constructor\r\n *\/\r\nconst Bytes2HexString = (b)=> {\r\n let hexs = \"\";\r\n for (let i = 0; i < b.length; i++) {\r\n let hex = (b[i]).toString(16);\r\n if (hex.length === 1) {\r\n hexs = '0' + hex;\r\n }\r\n hexs += hex.toUpperCase();\r\n }\r\n return hexs;\r\n}\r\n<\/pre>\n\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u6362btye\u578b<\/p>\n
\r\n\/**\r\n * \u5341\u516d\u8fdb\u5236\u8f6c\u6362btye\u578b\r\n * @param str\r\n * @returns {Promise}\r\n *\/\r\nconst Hexstring2btye = (str)=> {\r\n let pos = 0;\r\n let len = str.length;\r\n if (len % 2 != 0) {\r\n return null;\r\n }\r\n len \/= 2;\r\n let hexA = new Array();\r\n for (let i = 0; i < len; i++) {\r\n let s = str.substr(pos, 2);\r\n let v = parseInt(s, 16);\r\n hexA.push(v);\r\n pos += 2;\r\n }\r\n return hexA;\r\n}\r\n<\/pre>\n\u6a21\u62df\u5b9e\u73b0\uff0c\u4f7f\u7528\u8c37\u6b4c\u6700\u65b0\u7248\u5185\u6838\u6216\u8005\u652f\u6301ES6\u6d4f\u89c8\u5668\uff0c\u6309F12\u6253\u5f00\u8c03\u8bd5\u6a21\u5f0f\uff0c\u5c06\u4ee5\u4e0b\u4e24\u4e2a\u65b9\u6cd5\u8f93\u5165\uff08\u7c98\u5165\uff09\uff0c\u76f4\u63a5\u8c03\u7528\u5373\u53ef\u5728\u7ebf\u67e5\u770b\u3002<\/p>\n
\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n
1.\u8f93\u5165byte\u578b\u6570\u636e[160,100]\uff0c\u8c03\u7528Bytes2HexString\uff08[160,100]\uff09\uff0c\u53ef\u4ee5\u5f97\u5230\"A064\"\uff1b<\/p>\n
2.\u8f93\u5165\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u6570\u636e\"A064\"\uff0c\u8c03\u7528Hexstring2btye\uff08\"A064\"\uff09\uff0c\u53ef\u4ee5\u5f97\u5230[160,100]\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
byte\u578b\u8f6c\u6362\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32 \/** * byte\u578b\u8f6c\u6362\u5341\u516d\u8fdb\u5236 * @param b * @returns […]<\/p>\n","protected":false},"author":668,"featured_media":98456,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-127632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=127632"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127632\/revisions"}],"predecessor-version":[{"id":127793,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127632\/revisions\/127793"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/98456"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=127632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=127632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=127632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}