{"id":230,"date":"2016-04-20T16:17:08","date_gmt":"2016-04-20T08:17:08","guid":{"rendered":"http:\/\/blog.inforere.com\/?p=230"},"modified":"2017-06-29T18:21:11","modified_gmt":"2017-06-29T10:21:11","slug":"php%e8%bf%9b%e5%88%b6%e7%9a%84%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/blog.inforere.com\/?p=230","title":{"rendered":"php\u8fdb\u5236\u7684\u8f6c\u6362"},"content":{"rendered":"<h3><strong>\u4e00\uff0c\u5341\u8fdb\u5236\uff08decimal system\uff09\u8f6c\u6362\u51fd\u6570\u8bf4\u660e<\/strong><\/h3>\n<p>1\uff0c\u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236 decbin() \u51fd\u6570\uff0c\u5982\u4e0b\u5b9e\u4f8b<br \/>\necho decbin(12); \/\/\u8f93\u51fa 1100<br \/>\necho decbin(26); \/\/\u8f93\u51fa 11010<br \/>\ndecbin<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\ndecbin &#8212; \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nstring decbin ( int number )<br \/>\n\u8fd4\u56de\u4e00\u5b57\u7b26\u4e32\uff0c\u5305\u542b\u6709\u7ed9\u5b9a number \u53c2\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002\u6240\u80fd\u8f6c\u6362\u7684\u6700\u5927\u6570\u503c\u4e3a\u5341\u8fdb\u5236\u7684 4294967295\uff0c\u5176\u7ed3\u679c\u4e3a 32 \u4e2a 1 \u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>2\uff0c\u5341\u8fdb\u5236\u8f6c\u516b\u8fdb\u5236 decoct() \u51fd\u6570<\/p>\n<p>echo decoct(15); \/\/\u8f93\u51fa 17<br \/>\necho decoct(264); \/\/\u8f93\u51fa 410<br \/>\ndecoct<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\ndecoct &#8212; \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nstring decoct ( int number )<br \/>\n\u8fd4\u56de\u4e00\u5b57\u7b26\u4e32\uff0c\u5305\u542b\u6709\u7ed9\u5b9a number \u53c2\u6570\u7684\u516b\u8fdb\u5236\u8868\u793a\u3002\u6240\u80fd\u8f6c\u6362\u7684\u6700\u5927\u6570\u503c\u4e3a\u5341\u8fdb\u5236\u7684 4294967295\uff0c\u5176\u7ed3\u679c\u4e3a &#8220;37777777777&#8221;\u3002<\/p>\n<p>3\uff0c\u5341\u8fdb\u5236\u8f6c\u5341\u516d\u8fdb\u5236 dechex() \u51fd\u6570<\/p>\n<p>echo dechex(10); \/\/\u8f93\u51fa a<br \/>\necho dechex(47); \/\/\u8f93\u51fa 2f<br \/>\ndechex<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\ndechex &#8212; \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nstring dechex ( int number )<br \/>\n\u8fd4\u56de\u4e00\u5b57\u7b26\u4e32\uff0c\u5305\u542b\u6709\u7ed9\u5b9a number \u53c2\u6570\u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\u3002\u6240\u80fd\u8f6c\u6362\u7684\u6700\u5927\u6570\u503c\u4e3a\u5341\u8fdb\u5236\u7684 4294967295\uff0c\u5176\u7ed3\u679c\u4e3a &#8220;ffffffff&#8221;\u3002<\/p>\n<h3>\u4e8c\uff0c\u4e8c\u8fdb\u5236\uff08binary system\uff09\u8f6c\u6362\u51fd\u6570\u8bf4\u660e<\/h3>\n<p>1\uff0c\u4e8c\u8fdb\u5236\u8f6c\u5341\u516d\u5236\u8fdb bin2hex() \u51fd\u6570<\/p>\n<p>$binary = &#8220;11111001&#8221;;<br \/>\n$hex = dechex(bindec($binary));<br \/>\necho $hex;\/\/\u8f93\u51faf9<br \/>\nbin2hex<br \/>\n(PHP 3 &gt;= 3.0.9, PHP 4, PHP 5)<br \/>\nbin2hex &#8212; \u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u6210\u5341\u516d\u8fdb\u5236\u8868\u793a<br \/>\n\u8bf4\u660e<br \/>\nstring bin2hex ( string str )<br \/>\n\u8fd4\u56de ASCII \u5b57\u7b26\u4e32\uff0c\u4e3a\u53c2\u6570 str \u7684\u5341\u516d\u8fdb\u5236\u8868\u793a\u3002\u8f6c\u6362\u4f7f\u7528\u5b57\u8282\u65b9\u5f0f\uff0c\u9ad8\u56db\u4f4d\u5b57\u8282\u4f18\u5148\u3002<\/p>\n<p>2\uff0c\u4e8c\u8fdb\u5236\u8f6c\u5341\u5236\u8fdb bindec() \u51fd\u6570<\/p>\n<p>echo bindec(&#8216;110011&#8217;); \/\/\u8f93\u51fa 51<br \/>\necho bindec(&#8216;000110011&#8217;); \/\/\u8f93\u51fa 51<br \/>\necho bindec(&#8216;111&#8217;); \/\/\u8f93\u51fa 7<br \/>\nbindec<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\nbindec &#8212; \u4e8c\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nnumber bindec ( string binary_string )<br \/>\n\u8fd4\u56de binary_string \u53c2\u6570\u6240\u8868\u793a\u7684\u4e8c\u8fdb\u5236\u6570\u7684\u5341\u8fdb\u5236\u7b49\u4ef7\u503c\u3002<br \/>\nbindec() \u5c06\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6570\u8f6c\u6362\u6210 integer\u3002\u53ef\u8f6c\u6362\u7684\u6700\u5927\u7684\u6570\u4e3a 31 \u4f4d 1 \u6216\u8005\u8bf4\u5341\u8fdb\u5236\u7684 2147483647\u3002PHP 4.1.0 \u5f00\u59cb\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u5927\u6570\u503c\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u8fd4\u56de float \u7c7b\u578b\u3002<\/p>\n<h3>\u4e09\uff0c\u516b\u8fdb\u5236\uff08octal system\uff09\u8f6c\u6362\u51fd\u6570\u8bf4\u660e<\/h3>\n<p>\u516b\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236 octdec() \u51fd\u6570<\/p>\n<p>echo octdec(&#8217;77&#8217;); \/\/\u8f93\u51fa 63<br \/>\necho octdec(decoct(45)); \/\/\u8f93\u51fa 45<br \/>\noctdec<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\noctdec &#8212; \u516b\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nnumber octdec ( string octal_string )<br \/>\n\u8fd4\u56de octal_string \u53c2\u6570\u6240\u8868\u793a\u7684\u516b\u8fdb\u5236\u6570\u7684\u5341\u8fdb\u5236\u7b49\u503c\u3002\u53ef\u8f6c\u6362\u7684\u6700\u5927\u7684\u6570\u503c\u4e3a 17777777777 \u6216\u5341\u8fdb\u5236\u7684 2147483647\u3002PHP 4.1.0 \u5f00\u59cb\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u5927\u6570\u5b57\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u8fd4\u56de float \u7c7b\u578b<\/p>\n<h3>\u56db\uff0c\u5341\u516d\u8fdb\u5236\uff08hexadecimal\uff09\u8f6c\u6362\u51fd\u6570\u8bf4\u660e<\/h3>\n<p>\u5341\u516d\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236 hexdec()\u51fd\u6570<\/p>\n<p>var_dump(hexdec(&#8220;See&#8221;));<br \/>\nvar_dump(hexdec(&#8220;ee&#8221;));<br \/>\n\/\/ both print &#8220;int(238)&#8221;<\/p>\n<p>var_dump(hexdec(&#8220;that&#8221;)); \/\/ print &#8220;int(10)&#8221;<br \/>\nvar_dump(hexdec(&#8220;a0&#8221;)); \/\/ print &#8220;int(160)&#8221;<br \/>\nhexdec<br \/>\n(PHP 3, PHP 4, PHP 5)<br \/>\nhexdec &#8212; \u5341\u516d\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236<br \/>\n\u8bf4\u660e<br \/>\nnumber hexdec ( string hex_string )<br \/>\n\u8fd4\u56de\u4e0e hex_string \u53c2\u6570\u6240\u8868\u793a\u7684\u5341\u516d\u8fdb\u5236\u6570\u7b49\u503c\u7684\u7684\u5341\u8fdb\u5236\u6570\u3002hexdec() \u5c06\u4e00\u4e2a\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\u3002\u6240\u80fd\u8f6c\u6362\u7684\u6700\u5927\u6570\u503c\u4e3a 7fffffff\uff0c\u5373\u5341\u8fdb\u5236\u7684 2147483647\u3002PHP 4.1.0 \u5f00\u59cb\uff0c\u8be5\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u5927\u6570\u5b57\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u8fd4\u56de float \u7c7b\u578b\u3002<br \/>\nhexdec() \u5c06\u9047\u5230\u7684\u6240\u6709\u975e\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u66ff\u6362\u6210 0\u3002\u8fd9\u6837\uff0c\u6240\u6709\u5de6\u8fb9\u7684\u96f6\u90fd\u88ab\u5ffd\u7565\uff0c\u4f46\u53f3\u8fb9\u7684\u96f6\u4f1a\u8ba1\u5165\u503c\u4e2d\u3002<\/p>\n<h3>\u4e94\uff0c\u4efb\u610f\u8fdb\u5236\u8f6c\u6362 base_convert() \u51fd\u6570<\/h3>\n<p>$hexadecimal = &#8216;A37334&#8217;;<br \/>\necho base_convert($hexadecimal, 16, 2);\/\/\u8f93\u51fa 101000110111001100110100<br \/>\nbase_convert<br \/>\n(PHP 3 &gt;= 3.0.6, PHP 4, PHP 5)<\/p>\n<p>base_convert &#8212; \u5728\u4efb\u610f\u8fdb\u5236\u4e4b\u95f4\u8f6c\u6362\u6570\u5b57<br \/>\n\u8bf4\u660e<br \/>\nstring base_convert ( string number, int frombase, int tobase )<br \/>\n\u8fd4\u56de\u4e00\u5b57\u7b26\u4e32\uff0c\u5305\u542b number \u4ee5 tobase \u8fdb\u5236\u7684\u8868\u793a\u3002number \u672c\u8eab\u7684\u8fdb\u5236\u7531 frombase \u6307\u5b9a\u3002frombase \u548c tobase \u90fd\u53ea\u80fd\u5728 2 \u548c 36 \u4e4b\u95f4\uff08\u5305\u62ec 2 \u548c 36\uff09\u3002\u9ad8\u4e8e\u5341\u8fdb\u5236\u7684\u6570\u5b57\u7528\u5b57\u6bcd a-z \u8868\u793a\uff0c\u4f8b\u5982 a \u8868\u793a 10\uff0cb \u8868\u793a 11 \u4ee5\u53ca z \u8868\u793a 35\u3002<\/p>\n<p>\u8fd9\u91cc\u4e3b\u8981\u662f\u628aPHP\u8fdb\u5236\u8f6c\u6362\u51fd\u6570\u8fdb\u884c\u6574\u7406\uff0c\u4fbf\u4e8e\u5f00\u53d1\u67e5\u627e\uff0c\u76f8\u5173\u5177\u4f53\u51fd\u6570\u8bf4\u660e\u8bf7\u53c2\u8003PHP\u624b\u518c\u3002\u8bf7\u5173\u6ce8\u4e0b\u4e00\u671f\u4e2d\u6587\u5b57\u7b26\u7f16\u7801\u7814\u7a76\u7cfb\u5217\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\uff0c\u5341\u8fdb\u5236\uff08decimal system\uff09\u8f6c\u6362\u51fd\u6570\u8bf4\u660e 1\uff0c\u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236 decbin() \u51fd\u6570\uff0c\u5982\u4e0b\u5b9e\u4f8b  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,41],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/posts\/230"}],"collection":[{"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":1,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":231,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions\/231"}],"wp:attachment":[{"href":"https:\/\/blog.inforere.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inforere.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}