{"id":1583,"date":"2023-02-08T10:39:35","date_gmt":"2023-02-08T10:39:35","guid":{"rendered":"https:\/\/www.liutianfeng.com\/?p=1583"},"modified":"2023-05-10T09:07:08","modified_gmt":"2023-05-10T09:07:08","slug":"%e4%bd%8d%e8%bf%90%e7%ae%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=1583","title":{"rendered":"\u8fd0\u7b97\u7b26\u3001\u5360\u4f4d\u7b26"},"content":{"rendered":"\n<p><\/p>\n\n\n<h2>1\u3001\u4f4d\u8fd0\u7b97\u7b26<\/h2>\n<p>\u53c2\u8003\uff1ahttps:\/\/baike.baidu.com\/item\/%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6\/2786163?fr=aladdin<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">\u4e8c\u8fdb\u5236\u8f6c\u6362\uff1a\n2: 0010\n7: 0111\n&amp;: \u4e0e\n2 &amp; 7 = 0010 &amp; 0111 = 0010 = 2\n|: \u6216\n2 | 7 = 0010 | 0111 = 0111 = 7\n^: \u4ea6\u6216: \u76f8\u540c\u4e3a0, \u4e0d\u540c\u4e3a1\n2 ^ 7 = 0010 ^ 0111 = 0101 = 5\n&lt;&lt;, &gt;&gt;: \u5de6\u53f3\u79fb\u52a8\n2 &lt;&lt; 1 = 0010 &lt;&lt; 1 = 0100 = 4\n2 &gt;&gt; 1 = 0010 &gt;&gt; 1 = 0001 = 1\nfmt.Println(2&lt;&lt;1, 2&gt;&gt;1)\n# go run main.go\n4 1<\/code><\/pre>\n<h2>2\u3001\u5176\u5b83<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\">=, +=, -=, *=, \/=, %=, &amp;=, |=, ^=, &lt;&lt;=, &gt;&gt;=, &amp;^=<\/code><\/pre>\n<p>\u00a0<\/p>\n<h2>3\u3001\u5360\u4f4d\u7b26<\/h2>\n<p>https:\/\/www.cnblogs.com\/zhishuai\/p\/15620978.html<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">fmt.Printf(\"%5d\\n\", 10)   \/\/ \u6570\u5b57\u5199\u660e\u5bbd\u5ea6, \u9ed8\u8ba4\u53f3\u5bf9\u9f50\nfmt.Printf(\"%05d\\n\", 10)  \/\/ \u88650\nfmt.Printf(\"%-05d\\n\", 10) \/\/ \u5de6\u5bf9\u9f50[-], \u52a00\u4e5f\u4e0d\u663e\u793a\n\n# go run main.go\n   10\n00010\n10<\/code><\/pre>\n<p><strong>\u666e\u901a\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%v<\/td>\n<td>\u76f8\u5e94\u503c\u7684\u9ed8\u8ba4\u683c\u5f0f\u3002<\/td>\n<td>Printf(&#8220;%v&#8221;, people)<\/td>\n<td>{zhangsan}<\/td>\n<\/tr>\n<tr>\n<td>%+v<\/td>\n<td>\u6253\u5370\u7ed3\u6784\u4f53\u65f6\uff0c\u4f1a\u6dfb\u52a0\u5b57\u6bb5\u540d<\/td>\n<td>Printf(&#8220;%+v&#8221;, people)<\/td>\n<td>{Name:zhangsan}<\/td>\n<\/tr>\n<tr>\n<td>%#v<\/td>\n<td>\u76f8\u5e94\u503c\u7684Go\u8bed\u6cd5\u8868\u793a<\/td>\n<td>Printf(&#8220;#v&#8221;, people)<\/td>\n<td>main.Human{Name:&#8221;zhangsan&#8221;}<\/td>\n<\/tr>\n<tr>\n<td>%T<\/td>\n<td>\u76f8\u5e94\u503c\u7684\u7c7b\u578b\u7684Go\u8bed\u6cd5\u8868\u793a<\/td>\n<td>Printf(&#8220;%T&#8221;, people)<\/td>\n<td>main.Human<\/td>\n<\/tr>\n<tr>\n<td>%%<\/td>\n<td>\u5b57\u9762\u4e0a\u7684\u767e\u5206\u53f7\uff0c\u5e76\u975e\u503c\u7684\u5360\u4f4d\u7b26<\/td>\n<td>Printf(&#8220;%%&#8221;)<\/td>\n<td>%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Bool:<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%t<\/td>\n<td>true \u6216 false<\/td>\n<td>Printf(&#8220;%t&#8221;, true)<\/td>\n<td>true<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u6574\u6570\u5360\u4f4d\u7b26<button class=\"cnblogs-toc-button\" title=\"\u663e\u793a\u76ee\u5f55\u5bfc\u822a\" aria-expanded=\"false\"><\/button><\/strong><\/p>\n<div class=\"table-wrapper\">\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%b<\/td>\n<td>\u4e8c\u8fdb\u5236\u8868\u793a<\/td>\n<td>Printf(&#8220;%b&#8221;, 5)<\/td>\n<td>101<\/td>\n<\/tr>\n<tr>\n<td>%c<\/td>\n<td>\u76f8\u5e94Unicode\u7801\u70b9\u6240\u8868\u793a\u7684\u5b57\u7b26<\/td>\n<td>Printf(&#8220;%c&#8221;, 0x4E2D)<\/td>\n<td>\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>%d<\/td>\n<td>\u5341\u8fdb\u5236\u8868\u793a<\/td>\n<td>Printf(&#8220;%d&#8221;, 0x12)<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>%o<\/td>\n<td>\u516b\u8fdb\u5236\u8868\u793a<\/td>\n<td>Printf(&#8220;%d&#8221;, 10)<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>%q<\/td>\n<td>\u5355\u5f15\u53f7\u56f4\u7ed5\u7684\u5b57\u7b26\u5b57\u9762\u503c\uff0c\u7531Go\u8bed\u6cd5\u5b89\u5168\u5730\u8f6c\u4e49<\/td>\n<td>Printf(&#8220;%q&#8221;, 0x4E2D)<\/td>\n<td>&#8216;\u4e2d&#8217;<\/td>\n<\/tr>\n<tr>\n<td>%x<\/td>\n<td>\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u5b57\u6bcd\u5f62\u5f0f\u4e3a\u5c0f\u5199 a-f<\/td>\n<td>Printf(&#8220;%x&#8221;, 13)<\/td>\n<td>d<\/td>\n<\/tr>\n<tr>\n<td>%X<\/td>\n<td>\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u5b57\u6bcd\u5f62\u5f0f\u4e3a\u5927\u5199 A-F<\/td>\n<td>Printf(&#8220;%x&#8221;, 13)<\/td>\n<td>D<\/td>\n<\/tr>\n<tr>\n<td>%U<\/td>\n<td>Unicode\u683c\u5f0f\uff1aU+1234\uff0c\u7b49\u540c\u4e8e &#8220;U+%04X&#8221;<\/td>\n<td>Printf(&#8220;%U&#8221;, 0x4E2D)<\/td>\n<td>U+4E2D<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>\u6d6e\u70b9\u6570\u548c\u590d\u6570\u7684\u7ec4\u6210\u90e8\u5206\uff08\u5b9e\u90e8\u548c\u865a\u90e8\uff09<\/strong><\/p>\n<div class=\"table-wrapper\">\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%b<\/td>\n<td>\u65e0\u5c0f\u6570\u90e8\u5206\u7684\uff0c\u6307\u6570\u4e3a\u4e8c\u7684\u5e42\u7684\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0c \u4e0e strconv.FormatFloat \u7684 &#8216;b&#8217; \u8f6c\u6362\u683c\u5f0f\u4e00\u81f4\u3002\u4f8b\u5982 -123456p-78<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>%e<\/td>\n<td>\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0c\u4f8b\u5982 -1234.456e+78<\/td>\n<td>Printf(&#8220;%e&#8221;, 10.2)<\/td>\n<td>1.020000e+01<\/td>\n<\/tr>\n<tr>\n<td>%E<\/td>\n<td>\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0c\u4f8b\u5982 -1234.456E+78<\/td>\n<td>Printf(&#8220;%e&#8221;, 10.2)<\/td>\n<td>1.020000E+01<\/td>\n<\/tr>\n<tr>\n<td>%f<\/td>\n<td>\u6709\u5c0f\u6570\u70b9\u800c\u65e0\u6307\u6570\uff0c\u4f8b\u5982 123.456<\/td>\n<td>Printf(&#8220;%f&#8221;, 10.2)<\/td>\n<td>10.200000<\/td>\n<\/tr>\n<tr>\n<td>%g<\/td>\n<td>\u6839\u636e\u60c5\u51b5\u9009\u62e9 %e \u6216 %f \u4ee5\u4ea7\u751f\u66f4\u7d27\u51d1\u7684\uff08\u65e0\u672b\u5c3e\u76840\uff09\u8f93\u51fa<\/td>\n<td>Printf(&#8220;%g&#8221;, 10.20)<\/td>\n<td>10.2<\/td>\n<\/tr>\n<tr>\n<td>%G<\/td>\n<td>\u6839\u636e\u60c5\u51b5\u9009\u62e9 %E \u6216 %f \u4ee5\u4ea7\u751f\u66f4\u7d27\u51d1\u7684\uff08\u65e0\u672b\u5c3e\u76840\uff09\u8f93\u51fa<\/td>\n<td>Printf(&#8220;%G&#8221;, 10.20+2i)<\/td>\n<td>(10.2+2i)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>\u5b57\u7b26\u4e32\u4e0e\u5b57\u8282\u5207\u7247:<\/strong><\/p>\n<div class=\"table-wrapper\">\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%s<\/td>\n<td>\u8f93\u51fa\u5b57\u7b26\u4e32\u8868\u793a\uff08string\u7c7b\u578b\u6216[]byte)<\/td>\n<td>Printf(&#8220;%s&#8221;, []byte(&#8220;Go\u8bed\u8a00&#8221;))<\/td>\n<td>Go\u8bed\u8a00<\/td>\n<\/tr>\n<tr>\n<td>%q<\/td>\n<td>\u53cc\u5f15\u53f7\u56f4\u7ed5\u7684\u5b57\u7b26\u4e32\uff0c\u7531Go\u8bed\u6cd5\u5b89\u5168\u5730\u8f6c\u4e49<\/td>\n<td>Printf(&#8220;%q&#8221;, &#8220;Go\u8bed\u8a00&#8221;)<\/td>\n<td>&#8220;Go\u8bed\u8a00&#8221;<\/td>\n<\/tr>\n<tr>\n<td>%x<\/td>\n<td>\u5341\u516d\u8fdb\u5236\uff0c\u5c0f\u5199\u5b57\u6bcd\uff0c\u6bcf\u5b57\u8282\u4e24\u4e2a\u5b57\u7b26<\/td>\n<td>Printf(&#8220;%x&#8221;, &#8220;golang&#8221;)<\/td>\n<td>676f6c616e67<\/td>\n<\/tr>\n<tr>\n<td>%X<\/td>\n<td>\u5341\u516d\u8fdb\u5236\uff0c\u5927\u5199\u5b57\u6bcd\uff0c\u6bcf\u5b57\u8282\u4e24\u4e2a\u5b57\u7b26<\/td>\n<td>Printf(&#8220;%X&#8221;, &#8220;golang&#8221;)<\/td>\n<td>676F6C616E67<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>\u6307\u9488:<\/strong><\/p>\n<div class=\"table-wrapper\">\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>%p<\/td>\n<td>\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0c\u524d\u7f00 0x<\/td>\n<td>Printf(&#8220;%p&#8221;, &amp;people)<\/td>\n<td>0x4f57f0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>\u5176\u5b83\u6807\u8bb0\uff1a<\/strong><\/p>\n<div class=\"table-wrapper\">\n<table>\n<thead>\n<tr>\n<th>\u5360\u4f4d\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u4e3e\u4f8b<\/th>\n<th>\u8f93\u51fa<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>+<\/td>\n<td>\u603b\u6253\u5370\u6570\u503c\u7684\u6b63\u8d1f\u53f7\uff1b\u5bf9\u4e8e%q\uff08%+q\uff09\u4fdd\u8bc1\u53ea\u8f93\u51faASCII\u7f16\u7801\u7684\u5b57\u7b26\u3002<\/td>\n<td>Printf(&#8220;%+q&#8221;, &#8220;\u4e2d\u6587&#8221;)<\/td>\n<td>&#8220;\\u4e2d\\u6587&#8221;<\/td>\n<\/tr>\n<tr>\n<td>&#8211;<\/td>\n<td>\u5728\u53f3\u4fa7\u800c\u975e\u5de6\u4fa7\u586b\u5145\u7a7a\u683c\uff08\u5de6\u5bf9\u9f50\u8be5\u533a\u57df\uff09<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>#<\/td>\n<td>\u5907\u7528\u683c\u5f0f\uff1a\u4e3a\u516b\u8fdb\u5236\u6dfb\u52a0\u524d\u5bfc 0\uff08%#o\uff09 \u4e3a\u5341\u516d\u8fdb\u5236\u6dfb\u52a0\u524d\u5bfc 0x\uff08%#x\uff09\u6216 0X\uff08%#X\uff09\uff0c\u4e3a %p\uff08%#p\uff09\u53bb\u6389\u524d\u5bfc 0x\uff1b \u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c%q\uff08%#q\uff09\u4f1a\u6253\u5370\u539f\u59cb \uff08\u5373\u53cd\u5f15\u53f7\u56f4\u7ed5\u7684\uff09\u5b57\u7b26\u4e32\uff1b \u5982\u679c\u662f\u53ef\u6253\u5370\u5b57\u7b26\uff0c%U\uff08%#U\uff09\u4f1a\u5199\u51fa\u8be5\u5b57\u7b26\u7684 Unicode \u7f16\u7801\u5f62\u5f0f\uff08\u5982\u5b57\u7b26 x \u4f1a\u88ab\u6253\u5370\u6210 U+0078 &#8216;x&#8217;\uff09\u3002<\/td>\n<td>Printf(&#8220;%#U&#8221;, &#8216;\u4e2d&#8217;)<\/td>\n<td>U+4E2D<\/td>\n<\/tr>\n<tr>\n<td>&#8216; &#8216;<\/td>\n<td>(\u7a7a\u683c)\u4e3a\u6570\u503c\u4e2d\u7701\u7565\u7684\u6b63\u8d1f\u53f7\u7559\u51fa\u7a7a\u767d\uff08% d\uff09\uff1b \u4ee5\u5341\u516d\u8fdb\u5236\uff08% x, % X\uff09\u6253\u5370\u5b57\u7b26\u4e32\u6216\u5207\u7247\u65f6\uff0c\u5728\u5b57\u8282\u4e4b\u95f4\u7528\u7a7a\u683c\u9694\u5f00<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>\u586b\u5145\u524d\u5bfc\u76840\u800c\u975e\u7a7a\u683c\uff1b\u5bf9\u4e8e\u6570\u5b57\uff0c\u8fd9\u4f1a\u5c06\u586b\u5145\u79fb\u5230\u6b63\u8d1f\u53f7\u4e4b\u540e<\/td>\n<td>\u00a0<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<div class=\"table-wrapper\">\u00a0<\/div><p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=1583\">\u8fd0\u7b97\u7b26\u3001\u5360\u4f4d\u7b26<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4f4d\u8fd0\u7b97\u7b26 \u53c2\u8003\uff1ahttps:\/\/baike.baidu.com\/item\/%E4%BD%8D%E8%BF% [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1583"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1583"}],"version-history":[{"count":8,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions"}],"predecessor-version":[{"id":1723,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions\/1723"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}