{"id":652,"date":"2018-08-05T09:49:07","date_gmt":"2018-08-05T01:49:07","guid":{"rendered":"https:\/\/www.dd-home.top:1443\/?p=652"},"modified":"2018-08-05T09:49:07","modified_gmt":"2018-08-05T01:49:07","slug":"%e8%bf%9b%e5%88%b6%e8%bd%ac%e6%8d%a2%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=652","title":{"rendered":"\u8fdb\u5236\u8f6c\u6362\u5de5\u5177"},"content":{"rendered":"<p><!--more--><\/p>\n<pre class=\"lang:java decode:true \">\/**\n\t * int\u8f6c\u6362\u4e3a\u5c0f\u7aefbyte[]\uff08\u9ad8\u4f4d\u653e\u5728\u9ad8\u5730\u5740\u4e2d\uff09\n\t * \n\t * @param iValue\n\t * @return\n\t *\/\n\tpublic static byte[] Int2Bytes_LE(int iValue) {\n\t\tbyte[] rst = new byte[4];\n\t\t\/\/ \u5148\u5199int\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u8282\n\t\trst[0] = (byte) (iValue &amp; 0xFF);\n\t\t\/\/ int \u5012\u6570\u7b2c\u4e8c\u4e2a\u5b57\u8282\n\t\trst[1] = (byte) ((iValue &amp; 0xFF00) &gt;&gt; 8);\n\t\t\/\/ int \u5012\u6570\u7b2c\u4e09\u4e2a\u5b57\u8282\n\t\trst[2] = (byte) ((iValue &amp; 0xFF0000) &gt;&gt; 16);\n\t\t\/\/ int \u7b2c\u4e00\u4e2a\u5b57\u8282\n\t\trst[3] = (byte) ((iValue &amp; 0xFF000000) &gt;&gt; 24);\n\t\treturn rst;\n\t}\n\n\tpublic static int CRC_XModem(byte[] bytes) {\n\t\tint crc = 0x00; \/\/ initial value\n\t\tint polynomial = 0x1021;\n\t\tfor (int index = 0; index &lt; bytes.length; index++) {\n\t\t\tbyte b = bytes[index];\n\t\t\tfor (int i = 0; i &lt; 8; i++) {\n\t\t\t\tboolean bit = ((b &gt;&gt; (7 - i) &amp; 1) == 1);\n\t\t\t\tboolean c15 = ((crc &gt;&gt; 15 &amp; 1) == 1);\n\t\t\t\tcrc &lt;&lt;= 1;\n\t\t\t\tif (c15 ^ bit)\n\t\t\t\t\tcrc ^= polynomial;\n\t\t\t}\n\t\t}\n\t\tcrc &amp;= 0xffff;\n\t\treturn crc;\n\t}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[42,65],"class_list":["post-652","post","type-post","status-publish","format-standard","hentry","category-13","tag-byte","tag-65"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=652"}],"version-history":[{"count":0,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/652\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}