{"id":1745,"date":"2017-08-14T11:28:47","date_gmt":"2017-08-14T03:28:47","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=1745"},"modified":"2023-10-31T15:42:23","modified_gmt":"2023-10-31T07:42:23","slug":"java-convert-hex-to-string","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=1745","title":{"rendered":"[Java] Convert Hex to String"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">&lt;code&gt;\npublic static byte[] hexStringToByteArray(String s) {\n    int len = s.length();\n    byte[] data = new byte[len \/ 2];\n    for (int i = 0; i &amp;lt; len; i += 2) {\n        data[i \/ 2] = (byte) ((Character.digit(s.charAt(i), 16) &amp;lt;&amp;lt; 4)\n          + Character.digit(s.charAt(i+1), 16));\n    }\n    return data;\n}\n&lt;\/code&gt;<\/pre>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/140131\/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java\">stackoverflow: Convert a string representation of a hex dump to a byte array using Java?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;code&gt; public static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len \/ 2]; for (int i = 0; i &amp;lt; len; i += 2) { data[i \/ 2] = (byte) ((Character.digit(s.charAt(i), 16) &amp;lt;&amp;lt; 4) + &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=1745\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1745","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1745"}],"version-history":[{"count":3,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1745\/revisions"}],"predecessor-version":[{"id":1861,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1745\/revisions\/1861"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}