{"id":1902,"date":"2021-08-03T11:02:10","date_gmt":"2021-08-03T03:02:10","guid":{"rendered":"https:\/\/egonlin.com\/?p=1902"},"modified":"2022-02-07T16:50:23","modified_gmt":"2022-02-07T08:50:23","slug":"%e5%9f%ba%e6%9c%ac%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=1902","title":{"rendered":"\u57fa\u672c\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<h1>\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/h1>\n<h2>\u4e00 \u6570\u636e\u7c7b\u578b\u7684\u7531\u6765<\/h2>\n<p>\u200b   \u6570\u636e\u662f\u7a0b\u5e8f\u7684\u6838\u5fc3\uff0c\u6240\u6709\u7684\u7a0b\u5e8f\u90fd\u662f\u56f4\u7ed5\u6570\u636e\u7684\u64cd\u4f5c\u5c55\u5f00\u7684\u3002<\/p>\n<p>\u200b   \u7ad9\u5728\u7a0b\u5e8f\u5458\u7684\u89d2\u5ea6\uff0c\u7a0b\u5e8f\u4e2d\u7684\u6570\u636e\u662f\u7528\u6765\u63a7\u5236\u8ba1\u7b97\u673a\u786c\u4ef6<strong>\u8bb0\u5f55\u4e0b<\/strong>\u5e76\u4e14<strong>\u8868\u8fbe\u51fa<\/strong>\u4e8b\u7269\u72b6\u6001\u7684\uff0c\u8bb0\u5f55\u8d8a\u65b9\u4fbf\u3001\u8868\u8fbe\u8d8a\u6e05\u6670\uff0c\u7a0b\u5e8f\u5458\u7684\u5f00\u53d1\u5c06\u4f1a\u8d8a\u65b9\u4fbf\u3002<\/p>\n<p>\u200b   \u7ad9\u5728\u8ba1\u7b97\u673a\u5e95\u5c42\u786c\u4ef6\u7684\u89d2\u5ea6\u53bb\u770b\u5f85\u6570\u636e\uff0c\u6570\u636e\u5f53\u7136\u5168\u90fd\u662f\u7531bit\u4f4d\u7ec4\u6210\u7684\u3002\u4e3a\u4e86\u80fd\u591f\u8bb0\u5f55\u4e0b\u591a\u79cd\u72b6\u6001\uff0c\u6570\u636e\u4e0d\u662f\u7531\u5355\u4e2abit\u4f4d\u800c\u662f\u7531\u4e00\u7cfb\u5217\u7684bit\u4f4d\u7ec4\u6210\u7684\uff0c\u5e76\u4e14\u4e3a\u4e86\u80fd\u591f\u51c6\u786e\u5730\u8bfb\u53d6\uff0c\u7ec4\u6210\u6570\u636e\u7684bit\u4f4d\u4e2a\u6570\/\u957f\u5ea6\u56fa\u5b9a\uff0c\u6240\u4ee5\u8ba1\u7b97\u673a\u4e00\u822c\u64cd\u4f5c\u7684\u662f\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\uff0c\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u6bd4\u7279\u6570\u7ec4\u3001\u5185\u5b58\u5730\u5740\u3002\u8fdb\u4e00\u6b65\u5c06\u8fd9\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u7ec7\u5728\u4e00\u8d77\u5e76\u52a0\u4ee5\u547d\u540d\uff0c\u5c31\u53ef\u4ee5\u8bb0\u5f55\u4e0b\u5e76\u4e14\u5f88\u597d\u5730\u8868\u8fbe\u51fa\u66f4\u591a\u7684\u72b6\u6001\uff08\u6bd4\u5982\u4eba\u7684\u5e74\u9f84\u3001\u8eab\u9ad8\u3001\u59d3\u540d\u7b49\uff09\uff0c\u8fd9\u5c31\u662f\u7f16\u7a0b\u8bed\u8a00\u4e2d\u6570\u636e\u7c7b\u578b\u7684\u7531\u6765\u3002Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u7c7b\u578b\uff0c\u8fd9\u4e9b\u5185\u7f6e\u7684\u6570\u636e\u7c7b\u578b\uff0c\u517c\u987e\u4e86\u786c\u4ef6\u7684\u7279\u6027\u548c\u8868\u8fbe\u590d\u6742\u6570\u636e\u7ed3\u6784\u7684\u4fbf\u6377\u6027\u3002  <\/p>\n<pre><code class=\"language-go\">          \u7a0b\u5e8f\u4e2d            \u8ba1\u7b97\u673a\u5185\u5b58\u4e2d\n\u7a0b\u5e8f\u5458\u2014\u2014\u2014\u2014&gt;\u67d0\u79cd\u7c7b\u578b\u7684\u6570\u636e\u2014\u2014\u2014&gt; 0101010101\n\n\/\/ \u4f8b\u5982\uff1a\u8981\u6c42\u80fd\u591f\u5728\u8ba1\u7b97\u673a\u4e2d\u8bb0\u5f55\u4e0b\u4eba\u7684\u5e74\u9f84\u3001\u8eab\u9ad8\u3001\u59d3\u540d\u7b49\u72b6\u6001\uff0c\u5e76\u4e14\u80fd\u591f\u5728\u7a0b\u5e8f\u4e2d\u5f88\u597d\u5730\u8868\u8fbe\u51fa\u6765\u8fd9\u4e9b\u72b6\u6001\uff0c\u4ee5\u65b9\u4fbf\u7a0b\u5e8f\u5458\u7684\u5f00\u53d1\u3002\n\u7a0b\u5e8f\u5458\u2014\u2014\u2014\u2014&gt; \u4eba\u7684\u5e74\u9f84int \u2014\u2014\u2014\u2014&gt; 0101010111...\n\u7a0b\u5e8f\u5458\u2014\u2014\u2014\u2014&gt; \u4eba\u7684\u8eab\u9ad8float32 \u2014\u2014\u2014\u2014&gt; 0101011101...\n\u7a0b\u5e8f\u5458\u2014\u2014\u2014\u2014&gt; \u4eba\u7684\u59d3\u540dstring \u2014\u2014\u2014\u2014&gt; 1111111111...<\/code><\/pre>\n<p>\u200b   go\u5c5e\u4e8e\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\u4f1a\u5728\u7f16\u8bd1\u65f6\u5c31\u786e\u5b9a\u597d\u5185\u5b58\u7a7a\u95f4\u5927\uff0c\u8fd9\u6837\u7a0b\u5e8f\u8fd0\u884c\u65f6\u6548\u7387\u5c31\u9ad8\u4e86\uff0c\u4e0d\u7528\u8d39\u5fc3\u91cd\u65b0\u7533\u8bf7\u5185\u5b58<\/p>\n<h2>\u4e8c \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4ecb\u7ecd<\/h2>\n<p>Go\u8bed\u8a00\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u5206\u4e3a\u4e09\u5927\u7c7b<\/p>\n<ul>\n<li>1\u3001\u6570\u5b57\u7c7b\u578b\n<ul>\n<li>\u6574\u578b\uff1a int8\u3001 int16\u3001 int\u3001 uint\u3001 uintptr\u7b49<\/li>\n<li>\u6d6e\u70b9\u578b\uff1a float32\u3001 float64<\/li>\n<li>\u590d\u6570\uff1a complex64\u3001 complex128<\/li>\n<\/ul>\n<\/li>\n<li>2\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\uff1astring\uff0c\u5b57\u7b26\u7c7b\u578b\uff1abyte\u3001rune<\/li>\n<li>3\u3001\u5e03\u5c14\u578b\uff1abool<\/li>\n<\/ul>\n<h2>\u4e09 \u6570\u5b57\u7c7b\u578b\u4e4b\u6574\u578b<\/h2>\n<h3>3.1 \u6709\u7b26\u53f7\u4e0e\u65e0\u7b26\u53f7\u6574\u578b<\/h3>\n<p>Go\u8bed\u8a00\u4e2d\u63d0\u4f9b\u4e86\u4e0d\u540c\u7c7b\u578b\u7684\u6574\u578b\uff0c\u4e3b\u8981\u5206\u4e3a\u6709\u7b26\u53f7\u548c\u65e0\u7b26\u53f7\u4e24\u5927\u7c7b<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>uint8<\/td>\n<td>\u65e0\u7b26\u53f7 8\u4f4d\u6574\u578b (0 \u5230 255)\uff0c\u5bf9\u5e94go\u8bed\u8a00\u7684byte\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>uint16<\/td>\n<td>\u65e0\u7b26\u53f7 16\u4f4d\u6574\u578b (0 \u5230 65535)<\/td>\n<\/tr>\n<tr>\n<td>uint32<\/td>\n<td>\u65e0\u7b26\u53f7 32\u4f4d\u6574\u578b (0 \u5230 4294967295)<\/td>\n<\/tr>\n<tr>\n<td>uint64<\/td>\n<td>\u65e0\u7b26\u53f7 64\u4f4d\u6574\u578b (0 \u5230 18446744073709551615)<\/td>\n<\/tr>\n<tr>\n<td>int8<\/td>\n<td>\u6709\u7b26\u53f7 8\u4f4d\u6574\u578b (-128 \u5230 127)<\/td>\n<\/tr>\n<tr>\n<td>int16<\/td>\n<td>\u6709\u7b26\u53f7 16\u4f4d\u6574\u578b (-32768 \u5230 32767)\uff0c\u5bf9\u5e94C\u8bed\u8a00\u4e2d\u7684short\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>int32<\/td>\n<td>\u6709\u7b26\u53f7 32\u4f4d\u6574\u578b (-2147483648 \u5230 2147483647)\uff0c\u5bf9\u5e94go\u8bed\u8a00\u7684rune\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>int64<\/td>\n<td>\u6709\u7b26\u53f7 64\u4f4d\u6574\u578b (-9223372036854775808 \u5230 9223372036854775807)\uff0c\u5bf9\u5e94C\u8bed\u8a00\u4e2d\u7684long\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-go\">\/\/ \u4f8b\uff1a\nvar age uint8\nage = 256 \/\/ \u6ea2\u51fa\uff0c\u629b\u51fa\u5f02\u5e38\uff1aconstant 256 overflows uint8<\/code><\/pre>\n<h3>3.2 \u7279\u6b8a\u6574\u578b<\/h3>\n<p>\u6b64\u5916\u8fd8\u6709\u4e09\u4e2a\u7279\u6b8a\u7684\u6574\u578b\uff0c\u5176\u4e2dint\u662f\u6240\u6709\u6574\u578b\u91cc\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\uff0c\u4e5f\u662f\u7c7b\u578b\u63a8\u5bfc\u7684\u9ed8\u8ba4\u7c7b\u578b\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>uint<\/td>\n<td>\u572832\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eunit32\u4e00\u6837\uff0c 64\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eunit64\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>\u572832\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eint32\u4e00\u6837\uff0c 64\u4f4d\u5e73\u53f0\u4e0b\u5927\u5c0f\u4e0eint64\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>uintptr<\/td>\n<td>\u65e0\u7b26\u53f7\u6574\u578b\uff0c\u6ca1\u6709\u6307\u5b9a\u5177\u4f53\u7684bit\u5927\u5c0f\u4f46\u662f\u8db3\u4ee5\u5bb9\u7eb3\u6307\u9488\uff0c\u6240\u4ee5uintptr\u901a\u5e38\u7528\u4e8e\u5b58\u653e\u4e00\u4e2a\u6307\u9488\u3002uintptr\u7c7b\u578b\u53ea\u6709\u5728\u5e95\u5c42\u7f16\u7a0b\u662f\u624d\u9700\u8981\uff0c\u7279\u522b\u662fGo\u8bed\u8a00\u548cC\u8bed\u8a00\u51fd\u6570\u5e93\u6216\u64cd\u4f5c\u7cfb\u7edf\u63a5\u53e3\u76f8\u4ea4\u4e92\u7684\u5730\u65b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<p>1\u3001len()\u8fd4\u56de\u7684\u662f\u4e00\u4e2aint\u7c7b\u578b\uff0c\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u5207\u7247\u6216 map \u7684\u5143\u7d20\u6570\u91cf\u7b49\u90fd\u53ef\u4ee5\u7528<code>int<\/code>\u6765\u8868\u793a\u3002<\/p>\n<p>2\u3001\u5728\u6d89\u53ca\u5230\u4e8c\u8fdb\u5236\u4f20\u8f93\u3001\u8bfb\u5199\u6587\u4ef6\u7684\u7ed3\u6784\u63cf\u8ff0\u65f6\uff0c\u4e3a\u4e86\u4fdd\u6301\u6587\u4ef6\u7684\u7ed3\u6784\u4e0d\u4f1a\u53d7\u5230\u4e0d\u540c\u7f16\u8bd1\u76ee\u6807\u5e73\u53f0\u5b57\u8282\u957f\u5ea6\u7684\u5f71\u54cd\uff0c\u4e0d\u8981\u4f7f\u7528<code>int<\/code>\u548c <code>uint<\/code>\u3002<\/p>\n<h3>3.3 \u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h3>\n<p>go\u8bed\u8a00\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u6570\u636e\u7c7b\u578b\u6709\u660e\u786e\u7684\u8fb9\u754c\uff0c\u6bd4\u5982\uff0c\u5373\u4fbfint\u5728\u67d0\u4e00\u5e73\u53f0\u7684\u5927\u5c0f\u4e3a32\u4f4d\uff0cint\u548cint32\u4f9d\u7136\u4e0d\u540c\u7684\u7c7b\u578b\u3002\u5728\u9700\u8981\u5c06int\u5f53\u4f5cint32\u7c7b\u578b\u7684\u5730\u65b9\u7f16\u8bd1\u5668\u4e5f\u4e0d\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u505a\u7c7b\u578b\u8f6c\u6362\/\u9690\u5f0f\u8f6c\u6362\uff0c\u9700\u8981\u6211\u4eec\u81ea\u5df1\u505a\u663e\u5f0f\u7684\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\/\u5f3a\u5236\u8f6c\u6362\uff0c\u53cd\u4e4b\u4ea6\u7136\uff0c<\/p>\n<p>go\u8bed\u8a00\u63d0\u4f9b\u4e86\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u7684\u8bed\u6cd5\uff1aT(x)\uff0c\u53ea\u5141\u8bb8\u517c\u5bb9\u7c7b\u578b\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362<\/p>\n<pre><code class=\"language-go\">\u5bf9\u4e8e\u6bcf\u79cd\u7c7b\u578bT\uff0c\u5982\u679c\u8f6c\u6362\u5141\u8bb8\u7684\u8bdd\uff0c\u53ef\u4ee5\u7528\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5cT(x)\u5c06x\u8f6c\u6362\u4e3aT\u7c7b\u578b\uff08\u5176\u4e2d\uff0cT\u8868\u793a\u8981\u8f6c\u6362\u7684\u7c7b\u578b\u3002x\u4e3a\u8868\u8fbe\u5f0f\uff0c\u5305\u62ec\u53d8\u91cf\u3001\u590d\u6742\u7b97\u5b50\u548c\u51fd\u6570\u8fd4\u56de\u503c\u7b49.\uff09<\/code><\/pre>\n<p>\u8bb8\u591a\u6574\u5f62\u6570\u4e4b\u95f4\u7684\u76f8\u4e92\u8f6c\u6362\u5e76\u4e0d\u4f1a\u6539\u53d8\u6570\u503c\uff1b\u5b83\u4eec\u53ea\u662f\u544a\u8bc9\u7f16\u8bd1\u5668\u5982\u4f55\u89e3\u91ca\u8fd9\u4e2a\u503c\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">\/\/ \u4f8b1\uff1a\nvar x int32\ny := 666 \/\/ y\u5c06\u4f1a\u88ab\u81ea\u52a8\u63a8\u5bfc\u4e3aint\u7c7b\u578b\n\/\/ x = y \/\/ \u7f16\u8bd1\u9519\u8bef\uff0c\u56e0\u4e3ay\u662fint\u7c7b\u578b\uff0c\u800cx\u662fint32\u7c7b\u578b\uff0c\u6240\u4ee5\u65e0\u6cd5\u5c06y\u7684\u503c\u8d4b\u503c\u7ed9x\nx = int32(y) \/\/ \u4f7f\u7528\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u53ef\u4ee5\u89e3\u51b3\u4e0a\u8ff0\u9519\u8bef\uff0c\u6b64\u5904\u5e76\u6ca1\u6709\u6539\u53d8y\u7684\u503c\uff0c\u53ea\u662f\u544a\u8bc9\u4e86\u7f16\u8bd1\u5668y\u7684\u7c7b\u578b\u4e3aint32\uff0c\u4e0ex\u7684\u7c7b\u578b\u4fdd\u5b58\u4e00\u81f4\uff0c\u56e0\u6b64\u53ef\u4ee5\u8d4b\u503c\n\n\/\/ \u4f8b\u59822\uff1a\nvar apples int32 = 1\nvar oranges int16 = 2\n\/\/var compote int = apples + oranges  \/\/ \u7f16\u8bd1\u9519\u8bef\uff1a\u7b97\u672f\u548c\u903b\u8f91\u8fd0\u7b97\u7684\u4e8c\u5143\u64cd\u4f5c\u4e2d\u5fc5\u987b\u662f\u76f8\u540c\u7684\u7c7b\u578b\u3002\nvar compote = int(apples) + int(oranges)  \/\/ \u9700\u8981\u4e00\u4e2a\u663e\u5f0f\u7684\u8f6c\u6362\u5c06\u4e00\u4e2a\u503c\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u5316\u4f4d\u53e6\u4e00\u79cd\u7c7b\u578b\uff0c\u867d\u7136\u8fd9\u5076\u5c14\u4f1a\u5bfc\u81f4\u9700\u8981\u5f88\u957f\u7684\u8868\u8fbe\u5f0f\uff0c\u4f46\u662f\u5b83\u6d88\u9664\u4e86\u6240\u6709\u548c\u7c7b\u578b\u76f8\u5173\u7684\u95ee\u9898\uff0c\u800c\u4e14\u4e5f\u4f7f\u5f97\u7a0b\u5e8f\u5bb9\u6613\u7406\u89e3\u3002\nfmt.Println(compote) \/\/ 3<\/code><\/pre>\n<p>\u4f46\u662f\u5bf9\u4e8e\u5c06\u4e00\u4e2a\u5927\u5c3a\u5bf8\u7684\u6574\u6570\u7c7b\u578b\u8f6c\u4e3a\u4e00\u4e2a\u5c0f\u5c3a\u5bf8\u7684\u6574\u6570\u7c7b\u578b\uff08\u503c\u6ea2\u51fa\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\uff09\uff0c\u6216\u8005\u662f\u5c06\u4e00\u4e2a\u6d6e\u70b9\u6570\u8f6c\u4e3a\u6574\u6570\uff0c\u53ef\u80fd\u4f1a\u6539\u53d8\u6570\u503c\u6216\u4e22\u5931\u7cbe\u5ea6\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">f := 3.931 \/\/ f\u5c06\u4f1a\u88ab\u81ea\u52a8\u63a8\u5bfc\u4e3afloat64\u7c7b\u578b\ni := int(f)\nfmt.Println(f, i) \/\/ &quot;3.931 3&quot;\nf = 1.99\nfmt.Println(int(f)) \/\/ &quot;1&quot;<\/code><\/pre>\n<p>\u53e6\u5916\uff0c\u5bf9\u4e8e\u4e24\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u6574\u6570\u578b\u4e0d\u80fd\u76f4\u63a5\u6bd4\u8f83\uff0c\u4f46\u5404\u79cd\u7c7b\u578b\u7684\u6574\u578b\u53d8\u91cf\u90fd\u53ef\u4ee5\u76f4\u63a5\u4e0e\u5b57\u9762\u5e38\u91cf\u8fdb\u884c\u6bd4\u8f83\uff0c\u5982\u4e0b<\/p>\n<pre><code>var i int32\nvar j int64\n\ni, j = 1, 2\n\nif i == j {\u3000\u3000\/\/\u7f16\u8bd1\u9519\u8bef\n   fmt.Println(&quot;i and j are equal.&quot;)       \n}\n\nif i == 1 || j == 2 {\u3000\u3000\/\/\u7f16\u8bd1\u901a\u8fc7\n   fmt.Println(&quot;i and j are equal.&quot;)    \n}<\/code><\/pre>\n<h3>3.4 \u6570\u5b57\u5b57\u9762\u91cf\u8bed\u6cd5\uff08Number literals syntax\uff09<\/h3>\n<pre><code class=\"language-go\">Go1.13\u7248\u672c\u4e4b\u540e\u5f15\u5165\u4e86\u6570\u5b57\u5b57\u9762\u91cf\u8bed\u6cd5\uff0c\u8fd9\u6837\u4fbf\u4e8e\u5f00\u53d1\u8005\u4ee5\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\u6d6e\u70b9\u6570\u7684\u683c\u5f0f\u5b9a\u4e49\u6570\u5b57\uff0c\u4f8b\u5982\uff1a\n\n\/\/ \u65e0\u524d\u7f00\u4ee3\u8868\u5341\u8fdb\u5236\nv:=10\n\/\/ \u4ee50b\u4e3a\u524d\u7f00\u7684\u4e8c\u8fdb\u5236\nv := 0b00101101\n\/\/ \u4ee50o\u4e3a\u524d\u7f00\u7684\u516b\u8fdb\u5236\nv := 0o711 \n\/\/ \u4ee50x\u4e3a\u524d\u7f00\u7684\u5341\u516d\u8fdb\u5236\nv := 0xap-2\uff0c\u4ee3\u8868\u5341\u516d\u8fdb\u5236\u7684 a \u9664\u4ee5 2\u00b2\uff0c\u4e5f\u5c31\u662f\u5341\u8fdb\u5236\u768410\/4\u5f97 2.5\u3002\n\n\/\/ \u800c\u4e14\u8fd8\u5141\u8bb8\u6211\u4eec\u7528 _ \u6765\u5206\u9694\u6570\u5b57\nv := 123_456 \u7b49\u4e8e 123456\u3002<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u501f\u52a9fmt\u51fd\u6570\u6765\u5c06\u4e00\u4e2a\u6574\u6570\u4ee5\u4e0d\u540c\u8fdb\u5236\u5f62\u5f0f\u5c55\u793a\u3002<\/p>\n<pre><code class=\"language-go\">x:=57\n\/\/x:=0b111001 \n\/\/x:=0o71\n\/\/x:=0x39\n\n\/\/ \u8f93\u51fa(\u4e0d\u5e26\u524d\u7f00)\nfmt.Printf(&quot;%d\\n&quot;,x) \/\/ 57\nfmt.Printf(&quot;%b\\n&quot;,x) \/\/ 111001\nfmt.Printf(&quot;%o\\n&quot;,x) \/\/ 71\nfmt.Printf(&quot;%x\\n&quot;,x) \/\/ 39\n\n\/\/ \u8f93\u51fa(\u5e26\u524d\u7f00)\nfmt.Printf(&quot;%#d\\n&quot;,x) \/\/ 57\nfmt.Printf(&quot;%#b\\n&quot;,x) \/\/ 0b111001\nfmt.Printf(&quot;%#o\\n&quot;,x) \/\/ 071\nfmt.Printf(&quot;%#x\\n&quot;,x) \/\/ 0x39\n\n\/\/ [1]\u4ee3\u8868\u53d6\u5f97\u662f\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\uff0c[2]\u4ee3\u8868\u53d6\u5f97\u662f\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\nx:=57\ny:=33\nfmt.Printf(&quot;%[1]d   %[1]b   %[1]o  %[1]x\uff0c%[2]d   %[2]b   %[2]o  %[2]x &quot;,x,y)<\/code><\/pre>\n<h2>\u56db \u6570\u5b57\u7c7b\u578b\u4e4b\u6d6e\u70b9\u578b<\/h2>\n<p>Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e24\u79cd\u7cbe\u5ea6\u7684\u6d6e\u70b9\u6570\uff0c\u5355\u7cbe\u5ea6float32\u548c\u53cc\u7cbe\u5ea6float64\u3002\u5b83\u4eec\u7684\u7b97\u672f\u89c4\u8303\u7531IEEE754\u6d6e\u70b9\u6570\u56fd\u9645\u6807\u51c6\u5b9a\u4e49\uff0c\u8be5\u6d6e\u70b9\u6570\u89c4\u8303\u88ab\u6240\u6709\u73b0\u4ee3\u7684CPU\u652f\u6301\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u8303\u56f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>float32<\/td>\n<td>\u6700\u5c0f\u8fd1\u4f3c\u503c1.4e-45<br \/>\u6700\u5927\u8fd1\u4f3c\u503c\u5927\u7ea6\u662f3.4e38\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7math.MaxFloat32\u67e5\u770b<\/td>\n<\/tr>\n<tr>\n<td>float64<\/td>\n<td>\u6700\u5c0f\u8fd1\u4f3c\u503c4.9e-324<br \/>\u6700\u5927\u8fd1\u4f3c\u503c\u5927\u7ea6\u662f1.8e308\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7math.MaxFloat64\u67e5\u770b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u901a\u5e38\u5e94\u8be5\u4f18\u5148\u4f7f\u7528float64\uff0c\u56e0float64\u7684\u7cbe\u5ea6\u4ee5\u53ca\u8868\u793a\u7684\u6b63\u6574\u6570\u8303\u56f4\u90fd\u8981\u6bd4float32\u5927\uff0c\u5e76\u4e14\u7c7b\u578b\u63a8\u5bfc\u7684\u6d6e\u70b9\u578b\u9ed8\u8ba4\u5c31\u662ffloat64<\/p>\n<pre><code class=\"language-go\">\/\/ \u4f8b1\nz:=3.1415926 \nfmt.Printf(&quot;%T\\n&quot;, z)  \/\/ float64\nfmt.Printf(&quot;%8.3f\\n&quot;, z) \/\/ \u603b\u5bbd\u5ea6\u4e3a8\uff0c\u4fdd\u75593\u4f4d\u5c0f\u6570\uff08\u56db\u820d\u4e94\u5165\uff09\uff0c\u4e0d\u591f\u5728\u5de6\u4fa7\u586b\u5145\u7a7a\u683c\n\n\/\/ \u4f8b2\nvar x float32 = 12\ny:=12.0 \/\/ y\u88ab\u63a8\u5bfc\u51fa\u7684\u7c7b\u578b\u662ffloat64,\u800c\u4e0d\u7ba1\u8d4b\u7ed9\u5b83\u7684\u6570\u5b57\u662f\u5426\u662f\u752832\u4f4d\u957f\u5ea6\u8868\u793a\u7684\uff0c\u6ce8\u610f\u5982\u679c\u4e0d\u52a0\u5c0f\u6570\u70b9\uff0cy\u4f1a\u88ab\u63a8\u5bfc\u4e3a\u6574\u578b\u800c\u4e0d\u662f\u6d6e\u70b9\u578b\n\nfmt.Printf(&quot;%[1]T %.2[1]f\\n&quot;,x) \/\/ float32 12.00\nfmt.Printf(&quot;%[1]T %.2[1]f\\n&quot;,y) \/\/ float64 12.00<\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u5bf9\u4e8e\u4ee5\u4e0a\u7684\u4f8b\u5b50\uff0c\u4e0b\u9762\u7684\u8d4b\u503c\u5c06\u5bfc\u81f4\u7f16\u8bd1\u9519\u8bef\uff1a<\/p>\n<pre><code class=\"language-go\">y = x<\/code><\/pre>\n<p>\u5fc5\u987b\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/p>\n<pre><code class=\"language-go\">y = float64(x)<\/code><\/pre>\n<p><strong>\u6d6e\u70b9\u6570\u6bd4\u8f83<\/strong><br \/>\n\u56e0\u4e3a\u6d6e\u70b9\u6570\u4e0d\u662f\u4e00\u79cd\u7cbe\u786e\u7684\u8868\u8fbe\u65b9\u5f0f\uff0c\u6240\u4ee5\u50cf\u6574\u578b\u90a3\u6837\u76f4\u63a5\u7528==\u6765\u5224\u65ad\u4e24\u4e2a\u6d6e\u70b9\u6570\u662f\u5426\u76f8\u7b49<br \/>\n\u662f\u4e0d\u53ef\u884c\u7684\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0d\u7a33\u5b9a\u7684\u7ed3\u679c\uff0c\u4f8b\u5982<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n)\nfunc main() {\n    x := 0.1\n    y := 0.2\n\n    res := x + y\n    fmt.Println(res)        \/\/ 0.30000000000000004\n    fmt.Println(res == 0.3) \/\/ false\n\n}<\/code><\/pre>\n<p>\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848\u8be6\u89c1\u300a\u9644\u5f55\uff1a\u6d6e\u70b9\u6570\u7684\u7cbe\u5ea6\u95ee\u9898\u300b<\/p>\n<p>\u4e86\u89e3\uff1a\u6d6e\u70b9\u6570\u91cc\u6709\u4e2a\u53eb\u975e\u6570\u7684\u4e1c\u897f<\/p>\n<pre><code class=\"language-go\">fmt.Println(math.NaN()) \/\/ NaN\n\nvar z float32\nfmt.Println(z) \/\/ 0\nfmt.Println(z\/z) \/\/ NaN\n\nx:=z\/z\nfmt.Println(x &lt; x) \/\/ false\nfmt.Println(x &gt; x) \/\/ false \nfmt.Println(x == x) \/\/ false\nfmt.Println(x != x) \/\/ true<\/code><\/pre>\n<h2>\u4e94 \u6570\u5b57\u7c7b\u578b\u4e4b\u590d\u6570<\/h2>\n<pre><code>Go\u8bed\u8a00\u63d0\u4f9b\u4e86\u4e24\u79cd\u7cbe\u5ea6\u7684\u590d\u6570\u7c7b\u578b\uff1acomplex64\u548ccomplex128\uff0c\u590d\u6570\u5b9e\u9645\u4e0a\u7531\u4e24\u4e2a\u5b9e\u6570\uff08\u5728\u8ba1\u7b97\u673a\u4e2d\u7528\u6d6e\u70b9\u6570\u8868\u793a\uff0ccomplex64\u5bf9\u5e94\u7684\u662ffloat32\uff0ccomplex128\u5bf9\u5e94\u7684\u662ffloat64\uff09\u6784\u6210\uff0c\u4e00\u4e2a\u8868\u793a\u5b9e\u90e8\uff08real\uff09\uff0c\u4e00\u4e2a\u8868\u793a\u865a\u90e8\uff08imag\uff09\u3002<\/code><\/pre>\n<p>\u5185\u7f6e\u7684complex\u51fd\u6570\u7528\u4e8e\u6784\u5efa\u590d\u6570\uff0c\u5185\u5efa\u7684real\u548cimag\u51fd\u6570\u5206\u522b\u8fd4\u56de\u590d\u6570\u7684\u5b9e\u90e8\u548c\u865a\u90e8\uff1a<\/p>\n<pre><code class=\"language-go\">var x complex128 = complex(1, 2) \/\/ 1+2i\nvar y complex128 = complex(3, 4) \/\/ 3+4i\nfmt.Println(x*y)                 \/\/ &quot;(-5+10i)&quot;\nfmt.Println(real(x*y))           \/\/ &quot;-5&quot;\nfmt.Println(imag(x*y))           \/\/ &quot;10&quot;<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u4e2a\u6d6e\u70b9\u6570\u9762\u503c\u6216\u4e00\u4e2a\u5341\u8fdb\u5236\u6574\u6570\u9762\u503c\u540e\u9762\u8ddf\u7740\u4e00\u4e2ai\uff0c\u4f8b\u59823.141592i\u62162i\uff0c\u5b83\u5c06\u6784\u6210\u4e00\u4e2a\u590d\u6570\u7684\u865a\u90e8\uff0c\u590d\u6570\u7684\u5b9e\u90e8\u662f0\uff1a<\/p>\n<pre><code class=\"language-go\">fmt.Println(1i * 1i) \/\/ i^2 = -1 \uff0c\u5b9e\u90e8\u4e3a-1\uff0c\u865a\u90e8\u4e3a0\uff0c\u7ed3\u679c\u8bb0\u4e3a\u590d\u6570\u5f62\u5f0f(-1+0i)\n<\/code><\/pre>\n<p>\u5728\u5e38\u91cf\u7b97\u672f\u89c4\u5219\u4e0b\uff0c\u4e00\u4e2a\u590d\u6570\u5e38\u91cf\u53ef\u4ee5\u52a0\u5230\u53e6\u4e00\u4e2a\u666e\u901a\u6570\u503c\u5e38\u91cf\uff08\u6574\u6570\u6216\u6d6e\u70b9\u6570\u3001\u5b9e\u90e8\u6216\u865a\u90e8\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u81ea\u7136\u7684\u65b9\u5f0f\u4e66\u5199\u590d\u6570\uff0c\u5c31\u50cf1+2i\u6216\u4e0e\u4e4b\u7b49\u4ef7\u7684\u5199\u6cd52i+1\u3002\u4e0a\u9762x\u548cy\u7684\u58f0\u660e\u8bed\u53e5\u8fd8\u53ef\u4ee5\u7b80\u5316\uff1a<\/p>\n<pre><code class=\"language-Go\">x := 1 + 2i\ny := 3 + 4i<\/code><\/pre>\n<p>\u590d\u6570\u4e5f\u53ef\u4ee5\u7528==\u548c!=\u8fdb\u884c\u76f8\u7b49\u6bd4\u8f83\u3002\u53ea\u6709\u4e24\u4e2a\u590d\u6570\u7684\u5b9e\u90e8\u548c\u865a\u90e8\u90fd\u76f8\u7b49\u7684\u65f6\u5019\u5b83\u4eec\u624d\u662f\u76f8\u7b49\u7684\uff08\u8bd1\u6ce8\uff1a\u6d6e\u70b9\u6570\u7684\u76f8\u7b49\u6bd4\u8f83\u662f\u5371\u9669\u7684\uff0c\u9700\u8981\u7279\u522b\u5c0f\u5fc3\u5904\u7406\u7cbe\u5ea6\u95ee\u9898\uff09\u3002<\/p>\n<p>math\/cmplx\u5305\u63d0\u4f9b\u4e86\u590d\u6570\u5904\u7406\u7684\u8bb8\u591a\u51fd\u6570\uff0c\u4f8b\u5982\u6c42\u590d\u6570\u7684\u5e73\u65b9\u6839\u51fd\u6570\u548c\u6c42\u5e42\u51fd\u6570\uff0c\u66f4\u591a\u5173\u4e8e\u590d\u6570\u7684\u51fd\u6570\uff0c\u8bf7\u67e5\u9605math\/cmplx\u6807\u51c6\u5e93\u7684\u6587\u6863\u3002<\/p>\n<pre><code class=\"language-Go\">fmt.Println(cmplx.Sqrt(-1)) \/\/ &quot;(0+1i)&quot;<\/code><\/pre>\n<h2>\u516d \u5b57\u7b26\u4e32<\/h2>\n<p>\u200b   \u5728 C\/C++\u8bed\u8a00\u4e2d\uff0c\u5e76\u4e0d\u5b58\u5728\u539f\u751f\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\uff0c\u5b83\u4eec\u901a\u5e38\u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\u6765\u8868\u793a\u51fa\u5b57\u7b26\u4e32\u7684\u6982\u5ff5\uff0c\u5e76\u4ee5\u5b57\u7b26\u6307\u9488\u6765\u4f20\u9012\u3002\u800c\u5728Go\u8bed\u8a00\u4e2d\uff0c\u5b57\u7b26\u4e32\u4e5f\u662f\u4e00\u79cd\u57fa\u672c\u7c7b\u578b\uff0c\u5c31\u50cf\u5176\u4ed6\u6570\u636e\u7c7b\u578b\uff08int\u3001bool\u3001float32\u3001float64\u7b49\uff09\u4e00\u6837\u3002<\/p>\n<p>\u200b   Go\u8bed\u8a00\u4e2d\uff0c\u5b57\u7b26\u4e32\u5e95\u5c42\u662f\u4e00\u4e2a\u7531\u5b57\u8282(byte)\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u518d\u6b21\u5f3a\u8c03\uff1a\u5e95\u5c42\u6570\u7ec4\u5185\u5b58\u653e\u7684\u662f\u5b57\u8282byte\u3002<\/p>\n<p>\u200b   \u5b57\u7b26\u4e32\u7684\u503c\u9700\u8981\u7528\u53cc\u5f15\u53f7\u5305\u542b\uff0c\u53cc\u5f15\u53f7\u5185\u901a\u5e38\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\uff0c\u5373\u4eba\u7c7b\u4ece\u5b57\u9762\u4e0a\u5c31\u53ef\u4ee5\u8bfb\u61c2\u7684\u6587\u672c\u5b57\u7b26\uff0c\u6bd4\u5982<\/p>\n<pre><code class=\"language-go\">var msg string = &quot;hello, \u4e16\u754c&quot; \/\/ go\u4f1a\u5c06\u5b57\u9762\u91cf\u7684\u6587\u672c\u5b57\u7b26\u7f16\u7801\u6210utf-8\u683c\u5f0f\u7684\u5b57\u8282byte\u7136\u540e\u5b58\u5165\u5e95\u5c42\u6570\u7ec4\uff0c\u4e00\u4e2a\u82f1\u6587\u5b57\u7b26\u5360\u4e00\u4e2abyte\uff0c\u4e00\u4e2a\u4e2d\u6587\u5b57\u7b26\u53603\u4e2abyte<\/code><\/pre>\n<p>\u200b   \u4f46\u5176\u5b9e\u53cc\u5f15\u53f7\u5185\u53ef\u4ee5\u662f\u4efb\u610f\u5185\u5bb9\uff0c\u65e0\u8bba\u5b58\u4ec0\u4e48\u5185\u5bb9\uff0c\u5728\u6253\u5370\u5b57\u7b26\u4e32\u65f6\u4f1a\u4ece\u5e95\u5c42\u6570\u7ec4\u53d6\u51fabyte\u7136\u540e\u6309\u7167utf-8\u683c\u5f0f\u89e3\u7801\u6210\u5b57\u7b26<\/p>\n<pre><code class=\"language-go\">\/\/ 0\u3001\u5148\u50a8\u5907\u4e00\u4e2a\u77e5\u8bc6\u70b9\n\u4e00\u4e2a\u5b57\u8282=8\u4e2abit\u4f4d\n    \u5bf9\u5e94\u5341\u8fdb\u5236\u6700\u5927\u4e3a255\n    \u5bf9\u5e94\u7684\u5341\u516d\u8fdb\u5236\u6700\u5927\u4e3a0xff\n    \u5bf9\u5e94\u7684\u516b\u8fdb\u5236\u6700\u5927\u4e3a\\377(go\u4e2d\\\u5f00\u5934\u4ee3\u8868\u516b\u8fdb\u5236\uff0c\u4e0d\u8981\u5199\u6210\\o377)\n\n\/\/ 1\u3001\u53cc\u5f15\u53f7\u5185\u662f\u516b\u8fdb\u5236\u6570\u6784\u6210\u7684\u5b57\u7b26\u4e32\ns1:=&quot;\\110\\151&quot; \/\/ \u5e95\u5c42\u6570\u7ec4\u5b58\u653e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u662f\\110\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u8282\u662f\\151\nfmt.Println(s1) \/\/ Hi\nfmt.Println(len(s1)) \/\/ 2\u4e2a\u5b57\u8282\n\n\/\/ 2\u3001\u53cc\u5f15\u53f7\u5185\u662f\u5341\u516d\u8fdb\u5236\u6570\u6784\u6210\u7684\u5b57\u8282\ns2:=&quot;\\xe5\\xb3\\xb0\\xe5\\x93\\xa5&quot; \/\/ \u5e95\u5c42\u6570\u7ec4\u5b58\u653e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u662f\\xe5\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u8282\u662f\\xb3,\u4f9d\u6b21\u7c7b\u63a8...\nfmt.Println(s2) \/\/ \u5cf0\u54e5\nfmt.Println(len(s2)) \/\/ 6\u4e2a\u5b57\u8282\n\n\/\/ 3\u3001\u53cc\u5f15\u53f7\u5185\uff1a\\u\u6307\u7684\u662f\u9075\u5faaUCS-2\u6807\u51c6\u7684unicode\uff0c\\U\u6307\u7684\u662f\u9075\u5faaUCS-4\u6807\u7b7e\u7684unicode\ns3:=&quot;\\u771f\\U00005e05&quot; \/\/ \\u771f\u89e3\u7801\u6210utf-8\u7f16\u7801\u540e\u5bf9\u5e94\u4e09\u4e2a\u5b57\u8282\uff0c\u4f9d\u6b21\u5b58\u5165\u5e95\u5c42\u6570\u636e\uff0c\\U...\u4e00\u6837\nfmt.Println(s3) \/\/ \u771f\u5e05\nfmt.Println(len(s3)) \/\/ 6\u4e2a\u5b57\u8282\n\n\/\/ 4\u3001\u53cc\u5f15\u53f7\u5185\u662f\u5b57\u7b26\u4e32\u9762\u503c\ns4:=&quot;en\u8bf4\u7684\u5bf9&quot; \/\/ go\u4f1a\u5c06\u5b57\u7b26\u4e32\u9762\u503c\u7f16\u7801\u6210utf-8\u683c\u5f0f\uff0c\u7136\u540e\u5c06\u5f97\u5230\u7684byte\u4f9d\u6b21\u5b58\u5165\u5e95\u5c42\u6570\u7ec4\nfmt.Println(s4) \/\/ en\u8bf4\u7684\u5bf9\nfmt.Println(len(s4)) \/\/ 11\u4e2a\u5b57\u8282\n\n\/\/ \u53cc\u5f15\u53f7\u5185\u5b8c\u5168\u53ef\u4ee5\u540c\u65f6\u5bb9\u7eb3\u4e0a1\u30012\u30013\u30014\u6240\u8ff0\u7684\u5185\u5bb9\uff0c\u751a\u81f3\u987a\u5e8f\u90fd\u65e0\u6240\u8c13\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u5b57\u8282\u5e8f\u5217\u7684\u6570\u7ec4\uff0c\u81f3\u4e8e\u6570\u7ec4\u5185\u5b58\u7684\u662f\u4ec0\u4e48\u5b57\u8282byte\u662f\u65e0\u6240\u8c13\u7684\uff0c\u4f46\u95ee\u9898\u51fa\u5c31\u51fa\u5728\uff0c\u5f53\u6211\u4eec\u6253\u5370\u5b57\u7b26\u4e32\u7684\u65f6\u5019\uff0cgo\u4f1a\u5c06\u5b57\u7b26\u4e32\u5e95\u5c42\u6570\u7ec4\u4e2d\u7684byte\u53d6\u51fa\u6765\uff0c\u7136\u540e\u6309\u7167utf-8\u4e2a\u7684\u683c\u5f0f\u89e3\u7801\u6210\u5b57\u7b26\uff0c\u5982\u679cbyte\u975e\u6cd5\uff0c\u90a3\u4e48\u89e3\u7801\u51fa\u7684\u5b57\u7b26\u662f\u4e00\u4e2a\u9ed1\u8272\u516d\u89d2\u6216\u94bb\u77f3\u5f62\u72b6\uff0c\u91cc\u9762\u5305\u542b\u4e00\u4e2a\u767d\u8272\u7684\u95ee\u53f7\uff08?\uff09\ns5:=&quot;\\372\\xee\\xe5\\xb3\\xb0\\xe5\\x93\\xa5&quot; \/\/ \u524d2\u4e2a\u5b57\u8282\u90fd\u662f\u975e\u6cd5\u7684\uff0c\u540e6\u4e2a\u5408\u6cd5\nfmt.Println(s5) \/\/ \ufffd\ufffd\u5cf0\u54e5\nfmt.Println(len(s5)) \/\/ 8\u4e2a\u5b57\u8282<\/code><\/pre>\n<p>ps\uff1a\u6709\u4e00\u4e9b\u5b57\u7b26\u4e32\u9762\u503c\u7684\u5b57\u7b26\u6bd4\u8f83\u7279\u6b8a\uff0c\u6211\u4eec\u7528\u7684\u8f93\u5165\u6cd5\u5de5\u5177\u5f88\u96be\u8f93\u5165\uff0c\u6709\u4e00\u4e9b\u751a\u81f3\u662f\u4e0d\u53ef\u89c1\u7684\u5b57\u7b26\uff0c\u6b64\u65f6\u53ef\u4ee5\u5728Go\u8bed\u8a00\u7684\u5b57\u7b26\u4e32\u9762\u503c\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\u52a0\u4e0aUnicode\u7801\u70b9\u7684\u65b9\u5f0f\u6765\u8f93\u5165\u7279\u6b8a\u7684\u5b57\u7b26\uff08\u5982\u4e0a\u4f8b1\u30012\u30013\u30014\u6240\u793a\uff09\u3002unicode\u9075\u5faa\u4e24\u79cd\u6807\u51c6UCS-2\u548cUCS-4\uff0cUCS-2\u7528\u4e24\u4e2a\u5b57\u8282\u7f16\u7801\uff08\\u\u5bf9\u5e94UCS-2\uff09\uff0cUCS-4\u75284\u4e2a\u5b57\u8282\u7f16\u7801\uff08\\U\u5bf9\u5e94UCS-4\uff09\u3002\\uhhhh\u5bf9\u5e9416bit\u7684\u7801\u70b9\u503c\uff0c\\Uhhhhhhhh\u5bf9\u5e9432bit\u7684\u7801\u70b9\u503c\uff0c\u5176\u4e2dh\u662f\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff1b\u4e00\u822c\u5e38\u7528\u7684\u662f16bit\u7684\u5f62\u5f0f\uff0c\u5f88\u5c11\u9700\u8981\u4f7f\u752832bit\u7684\u5f62\u5f0f\uff0c\u8fd9\u6b63\u5982\u6211\u4eec\u5e38\u8bf4\u7684\u90a3\u6837\uff0cunicode\u901a\u5e38\u7528\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p><strong>\u7d22\u5f15\u64cd\u4f5c<\/strong><\/p>\n<pre><code class=\"language-go\">s:=&quot;hi\u4f60\u597d\u5440&quot;\n\n\/\/ \u6839\u636e\u7d22\u5f15\u53d6\u51fa\u7684\u662f\u7b2cn\u4e2a\u5b57\u8282\uff0c\u800c\u975e\u5b57\u7b26\nfmt.Println(s[0]) \/\/ 104\n\/\/fmt.Println(s[len(s1)]) \/\/ \u8d85\u51fa\u5b57\u7b26\u4e32\u7d22\u5f15\u8303\u56f4\u5bfc\u81f4panic\u5f02\u5e38\n\/\/fmt.Println(s[-1]) \/\/ \u4e0d\u652f\u6301\u8d1f\u5411\u7d22\u5f15\u5bfc\u81f4panic\u5f02\u5e38\n\n\/\/ ps\uff1a\ngo\u4e2ds[i]\u8bbf\u95ee\u7684\u90fd\u662f\u7b2ci\u4e2a\u5b57\u8282\u800c\u4e0d\u662f\u5b57\u7b26\uff0c\u56e0\u4e3ago\u7684\u5b57\u7b26\u4e32s\u7528\u7684\u662futf-8\u7f16\u7801,\u662f\u53d8\u957f\u7684\uff0c\u800c\u53d8\u957f\u7684\u7f16\u7801\u65e0\u6cd5\u901a\u8fc7\u7d22\u5f15\u64cd\u4f5c\u786e\u5b9a\u5b57\u7b26\u5360\u7528\u5b57\u8282\u7684\u4e2a\u6570\uff0c\u6240\u4ee5\u53ea\u80fd\u53d6\u5b57\u8282\u4e86\uff0c\u8fd9\u662f\u5b83\u7684\u7f3a\u70b9\uff1a\n\n\u800cpython\u4e2ds[i]\u8bbf\u95ee\u7684\u90fd\u662f\u7b2ci\u4e2a\u5b57\u7b26\uff0c\u56e0\u4e3apython3\u4e2d\u5b57\u7b26\u4e32\u7528\u662funicode\u7f16\u7801\uff0c\u662f\u5b9a\u957f\u7684<\/code><\/pre>\n<p><strong>\u53d6\u5b50\u5b57\u7b26\u4e32<\/strong><\/p>\n<pre><code class=\"language-go\">s1:=\"hi\u4f60\u597d\u5440\"\n\n\/\/ \u6b64\u5904\u53d6\u7684\u662f\u5b50\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u662f\u5b57\u8282\uff0c\u6240\u4ee5\u6253\u5370\u7ed3\u679c\u4f1a\u88ab\u89e3\u7801\u6210\u5b57\u7b26\n\/\/ \u987e\u5934\u4e0d\u987e\u5c3e\nfmt.Println(s1[0]) \/\/ 104\nfmt.Println(string(s1[0])) \/\/ h\n\nfmt.Println(s1[0:1]) \/\/ h\nfmt.Println(s1[0:2]) \/\/ hi\nfmt.Println(s1[0:3]) \/\/ hi\ufffd\nfmt.Println(s1[0:4]) \/\/ hi\ufffd\nfmt.Println(s1[0:5]) \/\/ hi\u4f60\nfmt.Println(s1[:5]) \/\/ hi\u4f60\uff0c\u9ed8\u8ba4\u4ece0\u5f00\u59cb\nfmt.Println(s1[2:]) \/\/ \u4f60\u597d\u5440\uff0c\u9ed8\u8ba4\u5230\u672b\u5c3e\nfmt.Println(s1[:]) \/\/  hi\u4f60\u597d\u5440\uff0c\u9ed8\u8ba4\u4ece\u5934\u5230\u672b\u5c3e<\/code><\/pre>\n<p><strong>\u5b57\u7b26\u4e32\u4e0d\u53ef\u4fee\u6539<\/strong><\/p>\n<pre><code class=\"language-go\">s:=&quot;hi\u4f60\u597d\u5440&quot;\ns[0] = &#039;L&#039; \/\/ \u7f16\u8bd1\u9519\u8bef: cannot assign to s[0]<\/code><\/pre>\n<p>\u4e0d\u53d8\u6027\u610f\u5473\u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u5171\u4eab\u76f8\u540c\u7684\u5e95\u5c42\u6570\u636e\u7684\u8bdd\u4e5f\u662f\u5b89\u5168\u7684\uff0c\u8fd9\u4f7f\u5f97<\/p>\n<ul>\n<li>\n<p>1\u3001\u590d\u5236\u4efb\u4f55\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u4ee3\u4ef7\u662f\u4f4e\u5ec9\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>2\u3001\u540c\u6837\uff0c\u4e00\u4e2a\u5b57\u7b26\u4e32s\u548c\u5bf9\u5e94\u7684\u5b50\u5b57\u7b26\u4e32\u5207\u7247s[7:]\u7684\u64cd\u4f5c\u4e5f\u53ef\u4ee5\u5b89\u5168\u5730\u5171\u4eab\u76f8\u540c\u7684\u5185\u5b58\uff0c\u56e0\u6b64\u5b57\u7b26\u4e32\u5207\u7247\u64cd\u4f5c\u4ee3\u4ef7\u4e5f\u662f\u4f4e\u5ec9\u7684\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e0b\u90fd\u6ca1\u6709\u5fc5\u8981\u5206\u914d\u65b0\u7684\u5185\u5b58\u3002 \u4e0b\u56fe\u6f14\u793a\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u548c\u4e24\u4e2a\u5b57\u4e32\u5171\u4eab\u76f8\u540c\u7684\u5e95\u5c42\u6570\u636e\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2021\/08\/\u5b57\u7b26\u4e32\u5171\u4eab\u5e95\u5c42\u6570\u7ec4.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2021\/08\/\u5b57\u7b26\u4e32\u5171\u4eab\u5e95\u5c42\u6570\u7ec4.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p><strong>\u8f6c\u4e49\u7b26\u53f7<\/strong><\/p>\n<p>\u5728\u4e00\u4e2a\u53cc\u5f15\u53f7\u5305\u542b\u7684\u5b57\u7b26\u4e32\u9762\u503c\u4e2d\uff0c\u53ef\u4ee5\u7528\u4ee5\u53cd\u659c\u6760<code>\\<\/code>\u5f00\u5934\u7684\u8f6c\u4e49\u5e8f\u5217\u63d2\u5165\u4efb\u610f\u7684\u6570\u636e\u3002\u4e0b\u9762\u7684\u6362\u884c\u3001\u56de\u8f66\u548c\u5236\u8868\u7b26\u7b49\u662f\u5e38\u89c1\u7684ASCII\u63a7\u5236\u4ee3\u7801\u7684\u8f6c\u4e49\u65b9\u5f0f\uff1a<\/p>\n<pre><code class=\"language-go\">\\n      \u6362\u884c\n\\r      \u56de\u8f66\n\\t      \u5236\u8868\u7b26\n\\&quot;      \u53cc\u5f15\u53f7 \n\\\\      \u53cd\u659c\u6760\n\/\/ \u4f8b\u5982\nfmt.Println(&quot;file_path := \\&quot;d:\\\\a\\\\b\\\\c.txt\\&quot;&quot;) \/\/ \u8f93\u51fa\uff1afile_path := &quot;d:\\a\\b\\c.txt&quot;\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a<\/p>\n<p>\u5b57\u7b26\u4e32\u662f\u5305\u542b\u5728\u53cc\u5f15\u53f7\u5185\u7684\uff0c\u5982\u679c\u53cc\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\u5185\u8fd8\u60f3\u518d\u5305\u542b\u53cc\u5f15\u53f7\uff0c\u90a3\u5c31\u9700\u8981\u8f6c\u4e49\u4e86\uff0c\u6b63\u5982\u4e0a\u4f8b\u6240\u793a\u3002\u4f46\u5982\u679c\u53cc\u5f15\u53f7\u5185\u5b58\u5728\u5355\u5f15\u53f7\uff0c\u65e0\u9700\u8f6c\u4e49\uff0c\u4f1a\u76f4\u63a5\u6253\u5370<\/p>\n<pre><code class=\"language-go\">fmt.Println(&quot;my name is &#039;egon&#039;&quot;) \/\/ my name is &#039;egon&#039;<\/code><\/pre>\n<p>\u5728go\u4e2d\u5355\u5f15\u53f7\u5185\u5305\u542b\u7684\u662f\u5b57\u7b26\u7c7b\u578b\uff0c\u5982\u679c\u5728\u5b57\u7b26\u7684\u5355\u5f15\u53f7\u5185\u8fd8\u60f3\u518d\u5305\u542b\u5355\u5f15\u53f7\u90a3\u4e5f\u9700\u8981\u8f6c\u4e49<\/p>\n<pre><code class=\"language-go\">fmt.Println(&#039;\\&#039;&#039;) \/\/ \u5355\u5f15\u53f7\u5185\u8868\u793a\u7684\u662f\u5b57\u7b26\u7c7b\u578b\uff0c\u53ea\u80fd\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\uff0c\u5982\u679c\u8be5\u5b57\u7b26\u662f\u5355\u5f15\u53f7\uff0c\u90a3\u4e48\u5fc5\u987b\u8f6c\u4e49<\/code><\/pre>\n<p><strong>\u53cd\u5f15\u53f7&#8220;<\/strong><\/p>\n<p>\u4f7f\u7528\u53cd\u5f15\u53f7\u4ee3\u66ff\u53cc\u5f15\u53f7\u4ee3\u8868\u662f\u539f\u751f\u5b57\u7b26\uff0c\u539f\u751f\u5b57\u7b26\u5185\u6ca1\u6709\u8f6c\u4e49\u64cd\u4f5c\uff0c\u5168\u90e8\u7684\u5185\u5bb9\u90fd\u662f\u5b57\u9762\u7684\u610f\u601d\uff0c\u4f1a\u539f\u6837\u8f93\u51fa\u5b57\u7b26\u4e0e\u6362\u884c\u7b49<\/p>\n<pre><code class=\"language-go\">s:=`\n\u5f53\u4f60\u8ba4\u6e05\u81ea\u5df1\u7684\u65f6\u5019\n\u4fbf\\n\\t\\n\\n\u4e0d\u4f1a\u518d\u5c0f\u77a7\u4ed6\u4eba\n\\u4e0a\n`\nfmt.Println(s) \/\/ \u8f93\u51fa\u5982\u4e0b\u5185\u5bb9\n\n\u5f53\u4f60\u8ba4\u6e05\u81ea\u5df1\u7684\u65f6\u5019\n\u4fbf\\n\\t\\n\\n\u4e0d\u4f1a\u518d\u5c0f\u77a7\u4ed6\u4eba\n\\u4e0a\n<\/code><\/pre>\n<p>\u539f\u751f\u5b57\u7b26\u4e32\u9762\u503c\u7528\u4e8e\u7f16\u5199\u6b63\u5219\u8868\u8fbe\u5f0f\u4f1a\u5f88\u65b9\u4fbf\uff0c\u56e0\u4e3a\u6b63\u5219\u8868\u8fbe\u5f0f\u5f80\u5f80\u4f1a\u5305\u542b\u5f88\u591a\u53cd\u659c\u6760\u3002\u539f\u751f\u5b57\u7b26\u4e32\u9762\u503c\u540c\u65f6\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8eHTML\u6a21\u677f\u3001JSON\u9762\u503c\u3001\u547d\u4ee4\u884c\u63d0\u793a\u4fe1\u606f\u4ee5\u53ca\u90a3\u4e9b\u9700\u8981\u6269\u5c55\u5230\u591a\u884c\u7684\u573a\u666f\u3002<\/p>\n<p><strong>\u4e86\u89e3unicode\u4e0eutf-8<\/strong><\/p>\n<pre><code class=\"language-go\">\/\/ ==========================&gt; unicode &lt;==========================\n\u5728\u5f88\u4e45\u4ee5\u524d\uff0c\u4e16\u754c\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\u7684\uff0c\u8d77\u7801\u8ba1\u7b97\u673a\u4e16\u754c\u5c31\u53ea\u6709\u4e00\u4e2aASCII\u5b57\u7b26\u96c6\uff1a\u7f8e\u56fd\u4fe1\u606f\u4ea4\u6362\u6807\u51c6\u4ee3\u7801\u3002ASCII\uff0c\u66f4\u51c6\u786e\u5730\u8bf4\u662f\u7f8e\u56fd\u7684ASCII\uff0c\u4f7f\u75287bit\u6765\u8868\u793a128\u4e2a\u5b57\u7b26\uff1a\u5305\u542b\u82f1\u6587\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u3001\u6570\u5b57\u3001\u5404\u79cd\u6807\u70b9\u7b26\u53f7\u548c\u8bbe\u7f6e\u63a7\u5236\u7b26\u3002\u5bf9\u4e8e\u65e9\u671f\u7684\u8ba1\u7b97\u673a\u7a0b\u5e8f\u6765\u8bf4\uff0c\u8fd9\u4e9b\u5c31\u8db3\u591f\u4e86\uff0c\u4f46\u662f\u8fd9\u4e5f\u5bfc\u81f4\u4e86\u4e16\u754c\u4e0a\u5f88\u591a\u5176\u4ed6\u5730\u533a\u7684\u7528\u6237\u65e0\u6cd5\u76f4\u63a5\u4f7f\u7528\u81ea\u5df1\u7684\u7b26\u53f7\u7cfb\u7edf\u3002\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0c\u6df7\u5408\u591a\u79cd\u8bed\u8a00\u7684\u6570\u636e\u53d8\u5f97\u5f88\u5e38\u89c1\uff08\u8bd1\u6ce8\uff1a\u6bd4\u5982\u672c\u8eab\u7684\u82f1\u6587\u539f\u6587\u6216\u4e2d\u6587\u7ffb\u8bd1\u90fd\u5305\u542b\u4e86ASCII\u3001\u4e2d\u6587\u3001\u65e5\u6587\u7b49\u591a\u79cd\u8bed\u8a00\u5b57\u7b26\uff09\u3002\u5982\u4f55\u6709\u6548\u5904\u7406\u8fd9\u4e9b\u5305\u542b\u4e86\u5404\u79cd\u8bed\u8a00\u7684\u4e30\u5bcc\u591a\u6837\u7684\u6587\u672c\u6570\u636e\u5462\uff1f\n\n\u7b54\u6848\u5c31\u662f\u4f7f\u7528Unicode(http:\/\/unicode.org) \uff0c\u5b83\u6536\u96c6\u4e86\u8fd9\u4e2a\u4e16\u754c\u4e0a\u6240\u6709\u7684\u7b26\u53f7\u7cfb\u7edf\uff0c\u5305\u62ec\u91cd\u97f3\u7b26\u53f7\u548c\u5176\u5b83\u53d8\u97f3\u7b26\u53f7\uff0c\u5236\u8868\u7b26\u548c\u56de\u8f66\u7b26\uff0c\u8fd8\u6709\u5f88\u591a\u795e\u79d8\u7684\u7b26\u53f7\uff0c\u5728\u7b2c\u516b\u7248\u672c\u7684Unicode\u6807\u51c6\u6536\u96c6\u4e86\u8d85\u8fc7120,000\u4e2a\u5b57\u7b26\uff0c\u6db5\u76d6\u8d85\u8fc7100\u591a\u79cd\u8bed\u8a00\u3002\u8fd9\u4e9b\u5728\u8ba1\u7b97\u673a\u7a0b\u5e8f\u548c\u6570\u636e\u4e2d\u662f\u5982\u4f55\u4f53\u73b0\u7684\u5462\uff1f\n\n\/\/ ==========================&gt; unicode\u5b57\u7b26\u4e0eunicode\u7801\u70b9 &lt;==========================\n\u6bcf\u4e2a\u7b26\u53f7\u90fd\u88ab\u6536\u5f55\u8fdb\u4e86unicode\u4e2d\uff0c\u79f0\u4e4b\u4e3aunicode\u5b57\u7b26\uff0c\u6bcf\u4e00\u4e2aunicode\u5b57\u7b26\u90fd\u88ab\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684Unicode\u683c\u5f0f\u7684\u6570\u5b57\uff0c\u8be5\u6570\u5b57\u79f0\u4e4b\u4e3aunincode\u7684\u7801\u70b9\uff0c\u901a\u7528\u7684\u8868\u793a\u4e00\u4e2aUnicode\u7801\u70b9\u7684\u6570\u636e\u7c7b\u578b\u662fint32\uff0c\u4e5f\u5c31\u662fGo\u8bed\u8a00\u4e2d\u7684rune\u7c7b\u578b\uff08rune\u662fint32\u7b49\u4ef7\u7c7b\u578b\uff09\uff1b\u5b83\u7684\u540c\u4e49\u8bcdrune\u7b26\u6587\u6b63\u662f\u8fd9\u4e2a\u610f\u601d\u3002\n\nunicode\u9075\u5faa\u4e24\u79cd\u6807\u51c6UCS-2\u548cUCS-4\uff0cUCS-2\u7528\u4e24\u4e2a\u5b57\u8282\u7f16\u7801\uff08go\u4e2d\u5bf9\u5e94\u7684\u8f6c\u4e49\u5b57\u7b26\u662f\\u\uff09\uff0cUCS-4\u75284\u4e2a\u5b57\u8282\u7f16\u7801\uff08go\u4e2d\u5bf9\u5e94\u7684\u8f6c\u4e49\u5b57\u7b26\u662f\\U\uff09\uff0c\\uhhhh\u5bf9\u5e9416bit\u7684\u7801\u70b9\u503c\uff0c\\Uhhhhhhhh\u5bf9\u5e9432bit\u7684\u7801\u70b9\u503c\uff0c\u5176\u4e2dh\u662f\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff1b\u4e00\u822c\u5f88\u5c11\u9700\u8981\u4f7f\u752832bit\u7684\u5f62\u5f0f\uff0c\u8fd9\u6b63\u5982\u6211\u4eec\u5e38\u8bf4\u7684\u90a3\u6837\uff0cunicode\u901a\u5e38\u7528\u4e24\u4e2a\u5b57\u8282\u8868\u793a\u4e00\u4e2a\u5b57\u7b26\u3002\n\n\u6211\u4eec*\u53ef\u4ee5*\u5c06\u4e00\u4e2a\u7b26\u6587\u5e8f\u5217\u8868\u793a\u4e3a\u4e00\u4e2aint32\u5e8f\u5217\u3002\u8fd9\u79cd\u7f16\u7801\u65b9\u5f0f\u53ebUTF-32\u6216UCS-4\uff0c\u6bcf\u4e2aUnicode\u7801\u70b9\u90fd\u4f7f\u7528\u540c\u6837\u7684\u5927\u5c0f32bit\u6765\u8868\u793a\u3002\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u7b80\u5355\u7edf\u4e00\uff0c\u4f46\u5982\u679c\u6587\u672c\u4e2d\u5305\u542b\u7684\u5927\u591a\u6570\u90fd\u662f\u82f1\u6587\u5b57\u7b26\u7684\u8bdd\uff0c\u5b83\u4f1a\u6d6a\u8d39\u5f88\u591a\u5b58\u50a8\u7a7a\u95f4\uff0c\u56e0\u4e3a\u4e00\u4e2a\u82f1\u6587\u5b57\u7b26\u53ea\u9700\u89818bit\u62161\u5b57\u8282\u5c31\u80fd\u8868\u793a\u3002\u800c\u4e14\u6211\u4eec\u5e38\u7528\u7684\u5b57\u7b26\u662f\u8fdc\u5c11\u4e8e65,536\u4e2a\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u752816bit\u7f16\u7801\u65b9\u5f0f\uff08UCS-2\uff09\u5c31\u80fd\u8868\u8fbe\u5e38\u7528\u5b57\u7b26\u3002\u4e3a\u4e86\u89e3\u51b3unicode\u7684\u95ee\u9898\uff0cutf-8\u5e94\u8fd0\u800c\u751f\u3002\n\n\/\/ ==========================&gt; utf-8 &lt;==========================\n\u524d\u8a00\uff1aUtf-8\u5c31\u662funicode\u7684\u4e00\u4e2a\u6807\u51c6\uff0c\u628aunicode\u7684\u5185\u5bb9\u8fdb\u884c\u4e86\u7f16\u6392\uff0c\u5b83\u672c\u8d28\u5176\u5b9e\u5c31\u662funicode\uff0cutf-8\u5168\u79f0\u4e5f\u662funicode\u7684\u4e00\u4e2a\u8f6c\u6362\u683c\u5f0f\uff0c\u5728\u5f97\u5230\u4e00\u4e2aunicode\u540e\uff0c\u6211\u4eec\u901a\u8fc7\u5c06\u5176\u6309\u7167utf-8\u7684\u683c\u5f0f\u7f16\u6392\u4e00\u4e0b\uff0c\u66f4\u7cbe\u7b80\u66f4\u7f8e\u597d\n\n\u8be6\u7ec6\uff1a\nUTF8\u7f16\u7801\u7531Go\u8bed\u8a00\u4e4b\u7236Ken Thompson\u548cRob Pike\u5171\u540c\u53d1\u660e\u7684\uff0c\u73b0\u5728\u5df2\u7ecf\u662fUnicode\u7684\u6807\u51c6\u3002\nUTF8\u5168\u79f0(Unicode Transformation Format 8), \u662f\u4e00\u79cd\u5c06Unicode\u7801\u70b9\u7f16\u7801\u4e3a\u5b57\u8282\u5e8f\u5217\u7684\u53d8\u957f\u7f16\u7801\u3002\nUTF8\u7f16\u7801\u4f7f\u75281\u52304\u4e2a\u5b57\u8282\u6765\u8868\u793a\u6bcf\u4e2aUnicode\u7801\u70b9\uff0c\u5176\u4e2d\n    - ASCII\u90e8\u5206\u5b57\u7b26\u53ea\u4f7f\u75281\u4e2a\u5b57\u8282\n    - \u5e38\u7528\u5b57\u7b26\u90e8\u5206\u4f7f\u75282\u62163\u4e2a\u5b57\u8282\u8868\u793a\u3002\n\u6bcf\u4e2a\u7b26\u53f7\u7f16\u7801\u540e\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u9ad8\u7aefbit\u4f4d\u7528\u4e8e\u8868\u793a\u603b\u5171\u6709\u591a\u5c11\u7f16\u7801\u4e2a\u5b57\u8282\u3002\u5982\u679c\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u9ad8\u7aefbit\u4e3a0\uff0c\u5219\u8868\u793a\u5bf9\u5e947bit\u7684ASCII\u5b57\u7b26\uff0cASCII\u5b57\u7b26\u6bcf\u4e2a\u5b57\u7b26\u4f9d\u7136\u662f\u4e00\u4e2a\u5b57\u8282\uff0c\u548c\u4f20\u7edf\u7684ASCII\u7f16\u7801\u517c\u5bb9\u3002\u5982\u679c\u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u9ad8\u7aefbit\u662f110\uff0c\u5219\u8bf4\u660e\u9700\u89812\u4e2a\u5b57\u8282\uff1b\u540e\u7eed\u7684\u6bcf\u4e2a\u9ad8\u7aefbit\u90fd\u4ee510\u5f00\u5934\u3002\u66f4\u5927\u7684Unicode\u7801\u70b9\u4e5f\u662f\u91c7\u7528\u7c7b\u4f3c\u7684\u7b56\u7565\u5904\u7406\u3002\n\n0xxxxxxx                             runes 0-127    (ASCII)\n110xxxxx 10xxxxxx                    128-2047       (values &lt;128 unused)\n1110xxxx 10xxxxxx 10xxxxxx           2048-65535     (values &lt;2048 unused)\n11110xxx 10xxxxxx 10xxxxxx 10xxxxxx  65536-0x10ffff (other values unused)\n\nutf-8\u8fd9\u79cd\u53d8\u957f\u7684\u7f16\u7801\uff0c\u56e0\u4e3a\u53d8\u957f\u800c\u5e26\u6765\u7684\u7f3a\u70b9\u662f\uff1a\u65e0\u6cd5\u76f4\u63a5\u901a\u8fc7\u7d22\u5f15\u6765\u8bbf\u95ee\u7b2cn\u4e2a\u5b57\u7b26(python3\u4e2d\u5b57\u7b26\u4e32\u88ab\u5b58\u6210unicode\u7684\u597d\u5904\u5c31\u662f\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u7b2cn\u4e2a\u5b57\u7b26\uff0c\u800c\u8fd9\u4e00\u70b9go\u8bed\u8a00\u662f\u505a\u4e0d\u5230\u7684)\n\u4f46\u662fUTF8\u4e5f\u56e0\u4e3a\u53d8\u957f\u83b7\u5f97\u4e86\u5f88\u591a\u989d\u5916\u7684\u4f18\u70b9\uff1a\u9996\u5148UTF8\u7f16\u7801\u6bd4\u8f83\u7d27\u51d1\uff0c\u5b8c\u5168\u517c\u5bb9ASCII\u7801\uff0c\u5e76\u4e14\u53ef\u4ee5\u81ea\u52a8\u540c\u6b65\uff1a\u5b83\u53ef\u4ee5\u901a\u8fc7\u5411\u524d\u56de\u6714\u6700\u591a2\u4e2a\u5b57\u8282\u5c31\u80fd\u786e\u5b9a\u5f53\u524d\u5b57\u7b26\u7f16\u7801\u7684\u5f00\u59cb\u5b57\u8282\u7684\u4f4d\u7f6e\u3002\u5b83\u4e5f\u662f\u4e00\u4e2a\u524d\u7f00\u7f16\u7801\uff0c\u6240\u4ee5\u5f53\u4ece\u5de6\u5411\u53f3\u89e3\u7801\u65f6\u4e0d\u4f1a\u6709\u4efb\u4f55\u6b67\u4e49\u4e5f\u5e76\u4e0d\u9700\u8981\u5411\u524d\u67e5\u770b\uff08\u8bd1\u6ce8\uff1a\u50cfGBK\u4e4b\u7c7b\u7684\u7f16\u7801\uff0c\u5982\u679c\u4e0d\u77e5\u9053\u8d77\u70b9\u4f4d\u7f6e\u5219\u53ef\u80fd\u4f1a\u51fa\u73b0\u6b67\u4e49\uff09\u3002\u6ca1\u6709\u4efb\u4f55\u5b57\u7b26\u7684\u7f16\u7801\u662f\u5176\u5b83\u5b57\u7b26\u7f16\u7801\u7684\u5b50\u4e32\uff0c\u6216\u662f\u5176\u5b83\u7f16\u7801\u5e8f\u5217\u7684\u5b57\u4e32\uff0c\u56e0\u6b64\u641c\u7d22\u4e00\u4e2a\u5b57\u7b26\u65f6\u53ea\u8981\u641c\u7d22\u5b83\u7684\u5b57\u8282\u7f16\u7801\u5e8f\u5217\u5373\u53ef\uff0c\u4e0d\u7528\u62c5\u5fc3\u524d\u540e\u7684\u4e0a\u4e0b\u6587\u4f1a\u5bf9\u641c\u7d22\u7ed3\u679c\u4ea7\u751f\u5e72\u6270\u3002\u540c\u65f6UTF8\u7f16\u7801\u7684\u987a\u5e8f\u548cUnicode\u7801\u70b9\u7684\u987a\u5e8f\u4e00\u81f4\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u6392\u5e8fUTF8\u7f16\u7801\u5e8f\u5217\u3002\u540c\u65f6\u56e0\u4e3a\u6ca1\u6709\u5d4c\u5165\u7684NUL(0)\u5b57\u8282\uff0c\u53ef\u4ee5\u5f88\u597d\u5730\u517c\u5bb9\u90a3\u4e9b\u4f7f\u7528NUL\u4f5c\u4e3a\u5b57\u7b26\u4e32\u7ed3\u5c3e\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\n\nGo\u8bed\u8a00\u7684\u6e90\u6587\u4ef6\u91c7\u7528UTF8\u7f16\u7801\uff0c\u5e76\u4e14Go\u8bed\u8a00\u5904\u7406UTF8\u7f16\u7801\u7684\u6587\u672c\u4e5f\u5f88\u51fa\u8272\u3002unicode\u5305\u63d0\u4f9b\u4e86\u8bf8\u591a\u5904\u7406rune\u5b57\u7b26\u76f8\u5173\u529f\u80fd\u7684\u51fd\u6570\uff08\u6bd4\u5982\u533a\u5206\u5b57\u6bcd\u548c\u6570\u7ec4\uff0c\u6216\u8005\u662f\u5b57\u6bcd\u7684\u5927\u5199\u548c\u5c0f\u5199\u8f6c\u6362\u7b49\uff09\uff0cunicode\/utf8\u5305\u5219\u63d0\u4f9b\u4e86\u7528\u4e8erune\u5b57\u7b26\u5e8f\u5217\u7684UTF8\u7f16\u7801\u548c\u89e3\u7801\u7684\u529f\u80fd\u3002\n\n\u66f4\u591a\u5173\u4e8e\u5b57\u7b26\u7f16\u7801\u7684\u77e5\u8bc6\u8bf7\u53c2\u8003\nhttps:\/\/www.cnblogs.com\/linhaifeng\/articles\/5950339.html\nhttps:\/\/baike.baidu.com\/item\/Unicode\/750500?fr=aladdin\nhttps:\/\/www.kancloud.cn\/lbb4511\/gopl\/1107841\nhttps:\/\/www.kancloud.cn\/lbb4511\/gopl\/1107842<\/code><\/pre>\n<p><strong>rune\u4e0ebyte<\/strong><\/p>\n<p>\u4ec0\u4e48\u662frune\uff1f<\/p>\n<pre><code class=\"language-go\">\/\/ rune\u7c7b\u578b\u4ecb\u7ecd\n\u5728unicode\u7f16\u7801\u91cc\uff0c\u6bcf\u4e2a\u5b57\u7b26\u90fd\u5bf9\u5e94\u4e3a\u4e00\u4e2a\u7801\u70b9\uff0c\u4e00\u4e2a\u7801\u70b9\u5c31\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u8be5\u6570\u5b57\u5bf9\u5e94go\u8bed\u8a00\u4e2d\u7684rune\u7c7b\u578b\uff08rune\u662fint32\u7b49\u4ef7\u7c7b\u578b\uff09\n\n\/\/ rune\u7c7b\u578b\u793a\u4f8b\nrune\u8868\u8fbe\u7684\u662f\u5b57\u7b26\u7c7b\u578b\uff0c\u5b58\u653e\u5b57\u7b26\u9700\u8981\u7528\u5355\u5f15\u53f7\u5305\u542b\uff0c\u6ce8\u610f\u5355\u5f15\u53f7\u5185\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u5b57\u7b26\ns1:=&#039;\u6c6a&#039;\nfmt.Println(s1)\nfmt.Printf(&quot;%T&quot;,s1) \/\/ int32,\u5373rune\u7c7b\u578b\n\ns2:=&#039;\u6c6a\u6c6a&#039; \/\/ \u7f16\u8bd1\u9519\u8bef\uff1ainvalid character literal (more than one character)\n\n\/\/ rune\u7c7b\u578b\u4e2d\u5305\u542b\u8f6c\u4e49\u7b26\n\u5355\u5f15\u53f7\u5b57\u7b26\u5fc5\u987b\u8f6c\u4e49\n&#039;\\&#039;&#039;\nUnicode\u8f6c\u4e49\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5728rune\u5b57\u7b26\u4e2d\u3002\u4e0b\u9762\u4e09\u4e2a\u5b57\u7b26\u662f\u7b49\u4ef7\u7684\uff1a\n&#039;\u4e16&#039; \n&#039;\\u4e16&#039; \n&#039;\\U00004e16&#039;\n\n\u5bf9\u4e8e\u5c0f\u4e8e256\u7801\u70b9\u503c\u53ef\u4ee5\u5199\u5728\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u8f6c\u4e49\u5b57\u8282\u4e2d\uff0c\u4f8b\u5982&#039;\\x41&#039;\u5bf9\u5e94\u5b57\u7b26&#039;A&#039;\uff0c\u4f46\u662f\u5bf9\u4e8e\u66f4\u5927\u7684\u7801\u70b9\u5219\u5fc5\u987b\u4f7f\u7528\\u\u6216\\U\u8f6c\u4e49\u5f62\u5f0f\uff0c\u56e0\u6b64\uff0c&#039;\\xe4\\xb8\\x96&#039;\u5e76\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684rune\u5b57\u7b26\uff0c\u867d\u7136\u8fd9\u4e09\u4e2a\u5b57\u8282\u5bf9\u5e94\u4e00\u4e2a\u6709\u6548\u7684UTF8\u7f16\u7801\u7684\u7801\u70b9\u3002\n\n\/\/ ps\n\u6574\u578b\u6570\u5b57\u8f6c\u6362\u6210ASCII\u5b57\u7b26\nnum := rune(90)\nfmt.Println(string(num))\n\n\u5b57\u7b26&#039;A&#039;\u88ab\u5b58\u6210\u4e86int32\uff0crune\u5c31\u662fint32\u7684\u522b\u540d\nx:=&#039;A&#039;\nfmt.Println(x)  \/\/ 65\nfmt.Printf(&quot;%T\\n&quot;,x)  \/\/ int32\nfmt.Println(string(x))  \/\/ A<\/code><\/pre>\n<p>\u4ec0\u4e48\u662fbyte\uff1f<\/p>\n<pre><code class=\"language-go\">\u5b57\u7b26\u4e32\u5e95\u5c42\u5c31\u662f\u4e00\u4e2a\u7531byte\u7ec4\u6210\u7684\u6570\u7ec4\n\/\/1\u3001\u5b58\u5b57\u7b26\u4e32\n1.1\u3001\u5b58\u7684\u65f6\u5019\uff0c\u5b57\u7b26\u4e32\u5185\u5305\u542b\u7684\u53ef\u4ee5\u76f4\u63a5\u5c31\u662f\u73b0\u6210\u7684\u4e00\u4e2a\u4e2abyte\uff0c\u5982s2:=&quot;\\xe5\\xb3\\xb0&quot;\uff0c\u5e76\u4e14\u6bcf\u4e00\u4e2abyte\u90fd\u53ef\u4ee5\u662f\u4efb\u610fbyte\n1.2\u3001\u4f46\u662f\uff0c\u5b58\u7684\u65f6\u5019\uff0c\u5b57\u7b26\u4e32\u5185\u5305\u542b\u7684\u4e5f\u53ef\u4ee5\u662f\u5b57\u7b26\/\u5b57\u7b26\u4e32\u9762\u503c\uff0c\u5982\u4e0b\u5b57\u7b26\u4e32\u7531\u5b57\u7b26\u4e32\u9762\u503c\u6784\u6210\uff0c\u4f1a\u6309\u7167utf-8\u683c\u5f0f\u7f16\u7801\u621013\u4e2a\u5b57\u8282\uff0c\u7136\u540e\u5b58\u5165\u5e95\u5c42\u6570\u7ec4\nimport &quot;unicode\/utf8&quot;\n\ns := &quot;Hello, \u4e16\u754c&quot;\nfmt.Println(len(s))                    \/\/ &quot;13&quot;\uff0c\u4ee3\u8868\u5e95\u5c42\u6570\u7ec4\u4e2d\u670913\u4e2a\u5b57\u8282\nfmt.Println(utf8.RuneCountInString(s)) \/\/ &quot;9&quot;\uff0c\u4ee3\u8868\u4e0a\u8ff013\u4e2a\u5b57\u8282\u5bf9\u5e949\u4e2aUnicode\u5b57\u7b26\uff1a\n\n\/\/2\u3001\u8bfb\u5b57\u7b26\u4e32\n\u6253\u5370\u5b57\u7b26\u4e32\u65f6\uff0c\u4f1a\u4ece\u5e95\u5c42\u6570\u7ec4\u4e2d\u53d6\u51fabyte\u7136\u540e\u6309\u7167utf-8\u4e2a\u683c\u5f0f\u8f6c\u6362\u6210\u5b57\u7b26\uff0c\u5982\u679c\u5f53\u521d\u5b58\u7684\u65f6\u5019\u65e0\u6cd5\u65e0\u5929\uff0c\u6253\u5370\u5b57\u7b26\u4e32\u7684\u65f6\u5019\u4fbf\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0\u4e71\u7801<\/code><\/pre>\n<p><strong>\u5faa\u73af\u5b57\u7b26\u4e32\u7684\u4e24\u79cd\u65b9\u5f0f<\/strong><\/p>\n<ul>\n<li>1\u3001\u4f9d\u8d56\u7d22\u5f15<\/li>\n<\/ul>\n<p><\/p><div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"1902\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"1902\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"f554e83dbc\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"ee095c8387\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u6570\u636e\u7c7b\u578b \u4e00 \u6570\u636e\u7c7b\u578b\u7684\u7531\u6765 \u200b \u6570\u636e\u662f\u7a0b\u5e8f\u7684\u6838\u5fc3\uff0c\u6240\u6709\u7684\u7a0b\u5e8f\u90fd\u662f\u56f4\u7ed5\u6570\u636e\u7684\u64cd\u4f5c\u5c55\u5f00\u7684\u3002 \u200b \u7ad9\u5728\u7a0b\u5e8f\u5458\u7684 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":2713,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[260,261,263,262],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1902"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1902"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1902\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/2713"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}