{"id":1416,"date":"2022-11-02T23:06:16","date_gmt":"2022-11-02T15:06:16","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1416"},"modified":"2022-11-27T12:39:45","modified_gmt":"2022-11-27T04:39:45","slug":"%e4%b8%80%e6%ac%a1%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%8c%e5%b0%86-%e5%ad%97%e7%ac%a6%e4%b8%b2-%e4%bf%9d%e5%ad%98%e5%9c%a8-byte-%e6%95%b0%e7%bb%84%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1416","title":{"rendered":"\u4e00\u6b21\u9762\u8bd5\u9898\uff0c\u5c06 \u5b57\u7b26\u4e32 \u4fdd\u5b58\u5728 Byte \u6570\u7ec4\u4e2d"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5728\u9762\u8bd5\uff0c\u9047\u5230\u4e00\u4e2a\u9762\u8bd5\u9898<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5b57\u7b26\u4e32 String str = \"AD428C93DE\" \u7f16\u7a0b\u5b9e\u73b0\u628a str \u7684\u5185\u5bb9\u653e\u5230 Byte[6] b \u7684\u6570\u7ec4\u4e2d\uff0c\u5b58\u5165\u540e\u5e76\u80fd\u6062\u590d\u539f\u6765\u7684\u5b57\u7b26\u4e32\u3002\r\n\r\n\u521d\u59cb\u770b\u5230\u8be5\u9898\uff0c\u6709\u70b9\u4e00\u6123\uff0c\u611f\u89c9\u7528 ascii \u7f16\u7801\u4e5f\u65e0\u6cd5\u4fdd\u5b58\u8fd9\u5b57\u7b26\u4e32\u554a\u3002\r\n\u540e\u6765\u624d\u660e\u767d\u4e00\u70b9\uff0c\u8981\u628a ABCDE \u5b57\u7b26\u5f53\u505a 16 \u8fdb\u5236\u4e2d\u7684 ABCDE\u5b58\u50a8\uff0c\u521a\u597d\u90fd\u662f\u5c0f\u4e8e 5\u4f4d\u5c31\u53ef\u4ee5\u4fdd\u5b58\u7684\uff0c\u8981\u662f\u591a\u4e2a F \u5c31\u65e0\u6cd5\u4fdd\u5b58\u4e86\u3002<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.util;\r\n\r\n\/**\r\n * @Author: Robert_mml\r\n * @Version 1.0 2019\/11\/6\r\n *\/\r\npublic class StringUtils {\r\n\r\n    public static void main(String&#91;] args) {\r\n        String a = \"AD428C93DE\";\r\n\r\n        byte&#91;] bytes = new byte&#91;6];\r\n\r\n        StringBuilder sb = new StringBuilder();\r\n\r\n        String&#91;] split = a.split(\"\");\r\n        for (int i = 0; i &lt; split.length; i++) {\r\n            sb.append(split&#91;i]);\r\n            if (i % 2 != 0) {\r\n                int str2HexInt = str2HexInt(sb.toString());\r\n                bytes&#91;i \/ 2] = (byte) str2HexInt;\r\n                sb.delete(0, 2);\r\n            }\r\n        }\r\n\r\n        for(byte b : bytes) {\r\n            if (b > 0) {\r\n                System.out.println(b);\r\n            } else {\r\n                System.out.println(256 + b);\r\n            }\r\n        }\r\n\r\n    }\r\n\r\n    static final char&#91;] chars = \"0123456789ABCDEF\".toCharArray();\r\n    public static int str2HexInt(String str){\r\n        char&#91;] chars1 = str.toCharArray();\r\n        int result = 0;\r\n        for (int i = 0; i &lt; chars1.length; i++) {\r\n            for (int j = 0; j &lt; chars.length; j++) {\r\n                if (chars1&#91;i] == chars&#91;j]) {\r\n                    result = (result &lt;&lt; 4) | j;\u3000\u3000\u3000\u3000\/\/ \u76f8\u5f53\u4e8e \u5c06 \u539f\u6570\u636e * 16 \u518d\u52a0\u4e0a \u65b0\u6570\u636e\uff0c 16\u8fdb\u5236\u8ba1\u7b97\u621010\u8fdb\u5236\r\n                }\r\n            }\r\n        }\r\n        return result;\r\n    }\r\n\r\n}<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u8bb0\u5f55\u5b57\u7b26\u4f4d\u7f6e\uff0c\u8fdb\u884c\u4fdd\u5b58\uff0c \u53ef\u4ee5\u5c06 ABCDEF \u5b57\u7b26\u8f6c\u6210 16 \u8fdb\u5236\u7684\u6570\u5b57\uff0c<\/p>\n\n\n\n<p>\u7136\u540e\u5c06\u4e24\u4e2a\u5b57\u7b26\u5b58\u5728\u4e00\u4e2a Byte \u91cc\uff0c \u6839\u672c\u5c31\u7528\u4e0d\u5230 6 \u4f4d\u6570\u7ec4\uff0c 5 \u4f4d\u5c31\u53ef\u4ee5\u641e\u5b9a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u9762\u8bd5\uff0c\u9047\u5230\u4e00\u4e2a\u9762\u8bd5\u9898 \u5b57\u7b26\u4e32 String str = &#8220;AD428C93DE&#8221; \u7f16\u7a0b\u5b9e\u73b0\u628a str \u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[46],"class_list":["post-1416","post","type-post","status-publish","format-standard","hentry","category-java-","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1416"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1416"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions"}],"predecessor-version":[{"id":1417,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1416\/revisions\/1417"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}