{"id":378,"date":"2011-10-16T18:37:16","date_gmt":"2011-10-16T10:37:16","guid":{"rendered":"http:\/\/my.no-ip.info\/carlos\/blog\/?p=378"},"modified":"2017-02-15T23:34:06","modified_gmt":"2017-02-15T15:34:06","slug":"%e6%b7%ba%e8%ab%87-unicode%e3%80%81utf-8%e3%80%81utf-16-%e5%92%8c-utf-32","status":"publish","type":"post","link":"https:\/\/carlos.aboutmy.info\/blog\/?p=378","title":{"rendered":"\u6dfa\u8ac7 Unicode\u3001UTF-8\u3001UTF-16 \u548c UTF-32"},"content":{"rendered":"<p>\u6dfa\u8ac7 Unicode\u3001UTF-8\u3001UTF-16 \u548c UTF-32<\/p>\n<p>\u96fb\u8166\u5176\u5be6\u53ea\u4ee5\u5132\u5b58\u548c\u8655\u7406\u6578\u5b57\uff0c\u800c\u96fb\u8166\u7684\u6578\u5b57\u662f\u4ee5\u4e8c\u9032\u5236\u7684\uff0c\u4ea6\u5373\u53ea\u6709 1 \u548c 0\uff0c\u8981\u96fb\u8166\u8655\u7406\u6587\u5b57\uff0c\u9996\u5148\u8981\u70ba\u6587\u5b57\u7de8\u4e0a\u4e00\u500b\u6578\u5b57\u3002<\/p>\n<p>\u800c Unicode \u5c31\u662f\u70ba\u6240\u6709\u5b57\u5143\u90fd\u7de8\u4e0a\u4e00\u500b\u7368\u6709\u7684\u6578\u5b57\uff0c\u7531\u65bc\u662f\u7368\u4e00\u7684\u6578\u5b57\uff0c\u540c\u4e00\u7de8\u78bc\u5c31\u53ea\u6703\u5c0d\u61c9\u4e00\u500b\u5b57\u5143\uff0c\u9019\u5c31\u53ef\u89e3\u6c7a\u4e82\u78bc\u7684\u554f\u984c\u3002\u4e4b\u65bc UTF-8\u3001UTF-16 \u548c UTF-32 \u5c31\u662f\u5982\u4f55\u5132\u5b58 Unicode \u7de8\u78bc\u7684\u65b9\u6cd5\uff0cUTF \u5168\u540d\u662f Unicode Transformation Format\u3002<\/p>\n<p>\u554f\u984c\u662f\u5168\u4e16\u754c\u6709\u9019\u9ebc\u591a\u5b57\u5143\uff0c\u6578\u5b57\u8981\u591a\u5927\u624d\u5920\uff1fUnicode 1.0 \u4ee5\u70ba 2 bytes\ufe5d\u5373\u662f 16-bit \u5c31\u8db3\u4ee5\u8655\u7406\uff0c\u6545\u6b64\u51fa\u73fe\u4e86 UTF-16 \/ UCS-2\ufe5e\u3002\u4f46\u597d\u5feb\u5c31\u767c\u89ba 2 bytes \u4e0d\u8db3\u4ee5\u70ba\u6240\u6709\u5b57\u5143\u7de8\u78bc\uff0c\u6545\u6b64\u5c31\u51fa\u73fe\u4e86 Unicode 2.0\uff0c\u5b83\u662f\u4ee5 21 bits \u7de8\u78bc\u3002\u76ee\u524d Unicode \u6700\u65b0\u6a19\u6e96\u662f Unicode 6.0\uff0c21 bits \u7a7a\u9593\u4ecd\u7136\u5341\u5206\u5145\u88d5\u3002<\/p>\n<p>UTF-16 \u539f\u610f\u662f\u4ee5\u56fa\u5b9a 2 bytes \u5132\u5b58\u4e00\u500b\u5b57\u5143\uff0c\u9019\u6a23\u904b\u7b97\u548c\u8655\u7406\u8d77\u4f86\u90fd\u5341\u5206\u65b9\u4fbf\u6709\u6548\u7387\uff0c\u7121\u5948 2 bytes \u7121\u6cd5\u70ba\u6240\u6709\u5b57\u5143\u7de8\u78bc\u3002UTF-16 \u7684\u505a\u6cd5\u662f\u5982\u679c FFFF \u7de8\u78bc\u5167\u7684\u5c31\u4ee5 2 bytes \u8868\u793a\uff0cFFFF \u4ee5\u4e0a\u5c31\u901a\u904e BMP (Basic Multilingual Plane) \u4ee5 4 bytes \u8868\u793a\u3002<\/p>\n<p>\u5728 FFFF \u7de8\u78bc\u5167\u7684\u5b57\u5143\uff0c\u4f8b\u5982\u82f1\u6587\u5b57\u6bcd\uff0cUTF-16 \u662f\u4ee5\u56fa\u5b9a 2 bytes \u7de8\u78bc\u3002\u4f8b\u5982 a \u5b57\u7684 Unicode \u7de8\u78bc\u662f 61\u3002\u5982\u679c\u4ee5 UTF-16 \u8868\u793a\u5c31\u662f 00 61\u3002\u800c\u7528 ASCII \u5247\u662f 61\u3002\u7531\u6b64\u53ef\u898b UTF-16 \u662f\u548c ASCII \u548c ISO-8859-1 \u4e0d\u76f8\u5bb9\u3002<\/p>\n<p>\u9806\u5e36\u4e00\u984c\uff0cASCII \u662f\u4ee5 7-bit \u7de8\u78bc\uff0c\u800c ISO-8859-1 \u662f\u4ee5 8-bit \u7de8\u78bc\uff0c\u5b83\u4ee5 ASCII \u70ba\u57fa\u790e\uff0c\u7528\u9918\u4e0b\u7684\u5728\u7a7a\u7f6e\u7684 0xA0-0xFF \u7684\u7bc4\u570d\u5167\uff0c\u52a0\u5165 96 \u500b\u5b57\u6bcd\u53ca\u7b26\u865f\u3002<\/p>\n<p>\u70ba\u89e3\u6c7a UTF-16 \u6709\u6642 2 bytes \u8868\u793a\uff0c\u6709\u6642 4 bytes \u7684\u554f\u984c\uff0c\u5c31\u51fa\u73fe\u4e86 UTF-32 \/ USC-4\u3002\u96d6\u7136 Unicode \u53ea\u7528\u4e0a 21 bit\uff0c\u4f46\u96fb\u8166\u8655\u7406\u7684\u4f4d\u5143\u6578\u591a\u4ee5 4 \u7684\u500d\u6578\u4e0a\uff0c\u5373\u662f 4 bit\u30018 bit\u300116 bit\u300132 bit\u300164 bit \u7b49\u3002\u6240\u4ee5 UTF-32 \u662f\u56fa\u5b9a\u4ee5 32 bit \u7de8\u78bc\u3002<\/p>\n<p>UTF-16 \u96d6\u7136\u540c ASCII \u4e0d\u76f8\u5bb9\uff0c\u4f46\u4f5c\u70ba\u5167\u90e8\u7de8\u78bc\u5247\u6c92\u6709\u9019\u554f\u984c\uff0c\u6240\u4ee5 UTF-16 \u88ab\u5ee3\u6cdb\u7528\u65bc\u7a0b\u5f0f\u7684\u5167\u90e8\u7de8\u78bc\uff0c\u5982 Java\u3002\u96d6\u7136 UTF-32 \u6709\u56fa\u5b9a\u7de8\u78bc\u7684\u597d\u8655\uff0c\u4f46\u7531\u65bc\u592a\u6d6a\u8cbb\u8a18\u61b6\u9ad4\uff0c\u52a0\u4e0a\u9700\u8981 BMP \u8f49\u63db\u7684\u60c5\u6cc1\u4e0d\u591a\uff0c\u4e5f\u7531\u65bc\u6b77\u53f2\u56e0\u7d20\uff0c\u4f8b\u5982\u7576\u5e74 Java \u9762\u4e16\u6642\uff0cUnicode \u9084\u662f\u4ee5 16 bit \u7de8\u78bc\u3002\u6240\u4ee5 UTF-32 \u73fe\u5728\u9084\u672a\u7b97\u666e\u53ca\u3002<\/p>\n<p>\u800c\u4f5c\u70ba\u5916\u90e8\u7de8\u78bc\ufe5d\u5373\u662f\u7528\u4f5c\u4ea4\u63db\u8cc7\u606f\ufe5eUTF-8 \u662f\u9996\u9078\u3002UTF-8 \u7684\u7de8\u78bc\u9577\u5ea6\u662f\u53ef\u8b8a\u7684\uff0c1 byte \u81f3 6 bytes \u90fd\u6709\u53ef\u80fd\uff0c\u5c0d\u65bc ASCII \u78bc\u7bc4\u570d\u5167\u7684\u5b57\u5143\uff0cUTF-8 \u7684\u8868\u793a\u65b9\u5f0f\u8ddf ASCII \u662f\u4e00\u6a23\u7684\uff0c\u90fd\u662f\u4f7f\u7528 1 byte\u3002\u76f8\u5bb9 ASCII \u52a0\u4e0a UTF-8 \u6c92\u6709\u5927\u5c0f\u5c3e\u5e8f\ufe5dBig \/ Little Endian\ufe5e \u4f7f UTF-8 \u4f5c\u70ba Unicode \u5916\u90e8\u7de8\u78bc\u7684\u4e0d\u4e8c\u4e4b\u9078\u3002<\/p>\n<p>UTF-8 \u4e0d\u4f7f\u7528\u5927\u5c3e\u5e8f\u548c\u5c0f\u5c3e\u5e8f\u3002\u9664\u4e86\u7b2c\u4e00\u500b byte \u5916\uff0c\u5176\u9918\u6bcf\u500b byte \u4f7f\u7528 10 \u958b\u59cb\uff0c\u7b2c 1 byte \u662f\u7528\u4f86\u8868\u793a\u9019\u500b\u5b57\u5143\u6703\u7528\u4e0a\u5e7e\u4e0a\u500b bytes\u3002\u4f8b\u5982 110 \u5373\u662f\u9019\u500b\u5b57\u5143\u6703\u7528\u4e0a 2 \u500b bytes\u3002<\/p>\n<p>1 byte  \u7684\u6642\u5019\uff1a0xxxxxxx<br \/>\n2 bytes \u7684\u6642\u5019\uff1a110xxxxx 10xxxxxx<br \/>\n3 bytes \u7684\u6642\u5019\uff1a1110xxxx 10xxxxxx 10xxxxxx<br \/>\n4 bytes \u7684\u6642\u5019\uff1a11110xxx 10xxxxxx 10xxxxxx 10xxxxxx<\/p>\n<p>\u7576 UTF-8 \u7528 4 bytes \u5132\u5b58\u5b57\u5143\u6642\uff0c\u6709 3 + (8 &#8211; 2) x 3 = 21 bits \u7de8\u78bc\u7a7a\u9593\uff0c\u8db3\u5920\u5132\u5b58\u6240\u6709 Unicode \u7de8\u78bc\u3002<\/p>\n<p>\u4ee5\u4e0b\u6211\u5c31\u4ee5\u300c\u8b1d\u300d\u5b57\u8b1b\u89e3 UTF-8 \u7de8\u78bc\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>\u900f\u904e\u300c\u5b57\u5143\u5c0d\u61c9\u8868\u300d\u6216 Hex Editor \ufe5d\u4ee5 UTF-16 \u7de8\u78bc\u7de8\u8f2f\ufe5e\u5f97\u77e5\u300c\u8b1d\u300d\u5b57\u7684 Unicode \u7de8\u78bc\u662f 8B1D\uff0c8B1D \u662f 16 \u9032\u5236\uff0c\u63db\u6210 2 \u9032\u5236\u5c31\u662f 1000101100011101\u3002<\/p>\n<p>\u5957\u4e0a UTF-8 \u7684\u5f62\u5f0f\uff1a<br \/>\n(1110)1000 (10)101100 (10)011101<\/p>\n<p>() \u5167\u7684\u6578\u5b57\u662f\u56e0\u61c9 UTF-8 \u7684\u8981\u6c42\u52a0\u4e0a\u53bb\u7684\uff0c\u7b2c 1 byte \u7684 1110 \u5c31\u8868\u793a\u4e86\u9019\u500b\u5b57\u5143\u9700\u8981 3 \u500b bytes\u3002<\/p>\n<p>\u63db\u6210 16 \u9032\u5236\uff0c\u300c\u8b1d\u300d\u5b57\u7684 UTF-8 \u7de8\u78bc\u5c31\u662f E8 AC 9D\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfa\u8ac7 Unicode\u3001UTF-8\u3001UTF-16 \u548c UTF-32 \u96fb\u8166\u5176\u5be6\u53ea\u4ee5\u5132\u5b58\u548c\u8655\u7406\u6578\u5b57\uff0c\u800c\u96fb\u8166\u7684\u6578\u5b57\u662f\u4ee5\u4e8c\u9032\u5236\u7684\uff0c\u4ea6\u5373\u53ea\u6709 1 \u548c 0\uff0c\u8981\u96fb\u8166\u8655\u7406\u6587\u5b57\uff0c\u9996\u5148\u8981\u70ba\u6587\u5b57\u7de8\u4e0a\u4e00\u500b\u6578\u5b57\u3002 \u800c Unicode \u5c31\u662f\u70ba\u6240\u6709\u5b57\u5143\u90fd\u7de8\u4e0a\u4e00\u500b\u7368\u6709\u7684\u6578\u5b57\uff0c\u7531\u65bc\u662f\u7368\u4e00\u7684\u6578\u5b57\uff0c\u540c\u4e00\u7de8\u78bc\u5c31\u53ea\u6703\u5c0d\u61c9\u4e00\u500b\u5b57\u5143\uff0c\u9019\u5c31\u53ef\u89e3\u6c7a\u4e82\u78bc\u7684\u554f\u984c\u3002\u4e4b\u65bc UTF-8\u3001UTF-16 \u548c UTF-32 \u5c31\u662f\u5982\u4f55\u5132\u5b58 Unicode \u7de8\u78bc\u7684\u65b9\u6cd5\uff0cUTF \u5168\u540d\u662f Unicode Transformation Format\u3002 \u554f\u984c\u662f\u5168\u4e16\u754c\u6709\u9019\u9ebc\u591a\u5b57\u5143\uff0c\u6578\u5b57\u8981\u591a\u5927\u624d\u5920\uff1fUnicode 1.0 \u4ee5\u70ba 2 bytes\ufe5d\u5373\u662f 16-bit \u5c31\u8db3\u4ee5\u8655\u7406\uff0c\u6545\u6b64\u51fa\u73fe\u4e86 UTF-16 \/ UCS-2\ufe5e\u3002\u4f46\u597d\u5feb\u5c31\u767c\u89ba 2 bytes \u4e0d\u8db3\u4ee5\u70ba\u6240\u6709\u5b57\u5143\u7de8\u78bc\uff0c\u6545\u6b64\u5c31\u51fa\u73fe\u4e86 Unicode 2.0\uff0c\u5b83\u662f\u4ee5 21 bits \u7de8\u78bc\u3002\u76ee\u524d Unicode \u6700\u65b0\u6a19\u6e96\u662f Unicode 6.0\uff0c21 bits \u7a7a\u9593\u4ecd\u7136\u5341\u5206\u5145\u88d5\u3002 UTF-16 \u539f\u610f\u662f\u4ee5\u56fa\u5b9a 2 bytes \u5132\u5b58\u4e00\u500b\u5b57\u5143\uff0c\u9019\u6a23\u904b\u7b97\u548c\u8655\u7406\u8d77\u4f86\u90fd\u5341\u5206\u65b9\u4fbf\u6709\u6548\u7387\uff0c\u7121\u5948 2 bytes \u7121\u6cd5\u70ba\u6240\u6709\u5b57\u5143\u7de8\u78bc\u3002UTF-16 \u7684\u505a\u6cd5\u662f\u5982\u679c FFFF\u2026 <span class=\"read-more\"><a href=\"https:\/\/carlos.aboutmy.info\/blog\/?p=378\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/378"}],"collection":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=378"}],"version-history":[{"count":2,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions\/570"}],"wp:attachment":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}