{"id":1111232,"date":"2025-01-08T17:27:10","date_gmt":"2025-01-08T09:27:10","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1111232.html"},"modified":"2025-01-08T17:27:12","modified_gmt":"2025-01-08T09:27:12","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e4%ba%8c%e8%bf%9b%e5%88%b6%e5%b0%8f%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1111232.html","title":{"rendered":"python\u5982\u4f55\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25073753\/ad3437f7-29ff-41ae-9e5c-58630cd9bfd6.webp\" alt=\"python\u5982\u4f55\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\" \/><\/p>\n<p><p> <strong>\u8981\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u89e3\u6790\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u3001\u5c06\u6574\u6570\u90e8\u5206\u4e58\u4ee52\u7684\u5e42\u6b21\u3001\u5c0f\u6570\u90e8\u5206\u4e58\u4ee52\u7684\u8d1f\u5e42\u6b21\u3002<\/strong> \u5176\u4e2d\u7684\u4e00\u4e2a\u5173\u952e\u6b65\u9aa4\u662f\u5c06\u5c0f\u6570\u90e8\u5206\u4e58\u4ee52\u7684\u8d1f\u5e42\u6b21\uff0c\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e8c\u8fdb\u5236\u5c0f\u65700.101\uff0c\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u65f6\uff0c\u9700\u8981\u8ba1\u7b971\u4e58\u4ee52\u7684-1\u6b21\u5e42\u52a0\u4e0a0\u4e58\u4ee52\u7684-2\u6b21\u5e42\u52a0\u4e0a1\u4e58\u4ee52\u7684-3\u6b21\u5e42\u3002<\/p>\n<\/p>\n<p><p>\u5177\u4f53\u7684\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def binary_to_decimal(binary_str):<\/p>\n<p>    # \u5206\u5272\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206<\/p>\n<p>    if &#39;.&#39; in binary_str:<\/p>\n<p>        integer_part, fractional_part = binary_str.split(&#39;.&#39;)<\/p>\n<p>    else:<\/p>\n<p>        integer_part, fractional_part = binary_str, &#39;0&#39;<\/p>\n<p>    # \u8ba1\u7b97\u6574\u6570\u90e8\u5206<\/p>\n<p>    decimal_integer = 0<\/p>\n<p>    for i, digit in enumerate(integer_part[::-1]):<\/p>\n<p>        decimal_integer += int(digit) * (2  i)<\/p>\n<p>    # \u8ba1\u7b97\u5c0f\u6570\u90e8\u5206<\/p>\n<p>    decimal_fraction = 0<\/p>\n<p>    for i, digit in enumerate(fractional_part):<\/p>\n<p>        decimal_fraction += int(digit) * (2  -(i + 1))<\/p>\n<p>    return decimal_integer + decimal_fraction<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>binary_str = &#39;101.101&#39;<\/p>\n<p>decimal_number = binary_to_decimal(binary_str)<\/p>\n<p>print(f&#39;\u4e8c\u8fdb\u5236\u5c0f\u6570 {binary_str} \u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u4e3a {decimal_number}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u5b9e\u73b0\u4e86\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u7684\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u5206\u5272\u5f00\u6765\uff0c\u7136\u540e\u5206\u522b\u8ba1\u7b97\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u503c\uff0c\u6700\u540e\u5c06\u4e24\u8005\u76f8\u52a0\u5f97\u5230\u6700\u7ec8\u7684\u5341\u8fdb\u5236\u5c0f\u6570\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e2a\u8fc7\u7a0b\u7684\u5404\u4e2a\u90e8\u5206\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u57fa\u672c\u6982\u5ff5<\/h3>\n<\/p>\n<p><h4>1\u3001\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u8868\u793a<\/h4>\n<\/p>\n<p><p>\u4e8c\u8fdb\u5236\u5c0f\u6570\u662f\u6307\u5728\u4e8c\u8fdb\u5236\u7cfb\u7edf\u4e2d\u7528\u6765\u8868\u793a\u5c0f\u6570\u7684\u5f62\u5f0f\u3002\u4e0e\u5341\u8fdb\u5236\u5c0f\u6570\u4e0d\u540c\u7684\u662f\uff0c\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6bcf\u4e00\u4f4d\u90fd\u8868\u793a2\u7684\u8d1f\u5e42\u6b21\u3002\u4f8b\u5982\uff0c\u4e8c\u8fdb\u5236\u5c0f\u6570<code>0.101<\/code>\u8868\u793a<code>1 * 2^-1 + 0 * 2^-2 + 1 * 2^-3<\/code>\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4e8c\u8fdb\u5236\u5c0f\u6570\u5230\u5341\u8fdb\u5236\u5c0f\u6570\u7684\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\uff0c\u9700\u8981\u5206\u522b\u8ba1\u7b97\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u503c\u3002\u6574\u6570\u90e8\u5206\u7684\u8f6c\u6362\u76f8\u5bf9\u7b80\u5355\uff0c\u53ea\u9700\u5c06\u6bcf\u4e00\u4f4d\u4e58\u4ee52\u7684\u5e42\u6b21\uff0c\u7136\u540e\u76f8\u52a0\u5373\u53ef\u3002\u800c\u5c0f\u6570\u90e8\u5206\u7684\u8f6c\u6362\u5219\u9700\u8981\u5c06\u6bcf\u4e00\u4f4d\u4e58\u4ee52\u7684\u8d1f\u5e42\u6b21\uff0c\u7136\u540e\u76f8\u52a0\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6574\u6570\u90e8\u5206\u7684\u8f6c\u6362<\/h3>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u6574\u6570\u90e8\u5206<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6574\u6570\u90e8\u5206\uff0c\u4e8c\u8fdb\u5236\u6570\u7684\u6bcf\u4e00\u4f4d\u8868\u793a2\u7684\u5e42\u6b21\u3002\u4f8b\u5982\uff0c\u4e8c\u8fdb\u5236\u6570<code>101<\/code>\u8868\u793a<code>1 * 2^2 + 0 * 2^1 + 1 * 2^0<\/code>\u3002\u6211\u4eec\u53ef\u4ee5\u4ece\u53f3\u5230\u5de6\u4f9d\u6b21\u8ba1\u7b97\u6bcf\u4e00\u4f4d\u7684\u503c\uff0c\u7136\u540e\u76f8\u52a0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_integer_part(integer_part):<\/p>\n<p>    decimal_integer = 0<\/p>\n<p>    for i, digit in enumerate(integer_part[::-1]):<\/p>\n<p>        decimal_integer += int(digit) * (2  i)<\/p>\n<p>    return decimal_integer<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">integer_part = &#39;101&#39;<\/p>\n<p>decimal_integer = calculate_integer_part(integer_part)<\/p>\n<p>print(f&#39;\u6574\u6570\u90e8\u5206 {integer_part} \u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\u4e3a {decimal_integer}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5c0f\u6570\u90e8\u5206\u7684\u8f6c\u6362<\/h3>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u5c0f\u6570\u90e8\u5206<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5c0f\u6570\u90e8\u5206\uff0c\u4e8c\u8fdb\u5236\u6570\u7684\u6bcf\u4e00\u4f4d\u8868\u793a2\u7684\u8d1f\u5e42\u6b21\u3002\u4f8b\u5982\uff0c\u4e8c\u8fdb\u5236\u5c0f\u6570<code>0.101<\/code>\u8868\u793a<code>1 * 2^-1 + 0 * 2^-2 + 1 * 2^-3<\/code>\u3002\u6211\u4eec\u53ef\u4ee5\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u8ba1\u7b97\u6bcf\u4e00\u4f4d\u7684\u503c\uff0c\u7136\u540e\u76f8\u52a0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_fractional_part(fractional_part):<\/p>\n<p>    decimal_fraction = 0<\/p>\n<p>    for i, digit in enumerate(fractional_part):<\/p>\n<p>        decimal_fraction += int(digit) * (2  -(i + 1))<\/p>\n<p>    return decimal_fraction<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">fractional_part = &#39;101&#39;<\/p>\n<p>decimal_fraction = calculate_fractional_part(fractional_part)<\/p>\n<p>print(f&#39;\u5c0f\u6570\u90e8\u5206 {fractional_part} \u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u6570\u4e3a {decimal_fraction}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b8c\u6574\u7684\u8f6c\u6362\u8fc7\u7a0b<\/h3>\n<\/p>\n<p><p>\u5c06\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u7684\u8ba1\u7b97\u7ed3\u679c\u76f8\u52a0\uff0c\u5f97\u5230\u6700\u7ec8\u7684\u5341\u8fdb\u5236\u5c0f\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def binary_to_decimal(binary_str):<\/p>\n<p>    if &#39;.&#39; in binary_str:<\/p>\n<p>        integer_part, fractional_part = binary_str.split(&#39;.&#39;)<\/p>\n<p>    else:<\/p>\n<p>        integer_part, fractional_part = binary_str, &#39;0&#39;<\/p>\n<p>    decimal_integer = calculate_integer_part(integer_part)<\/p>\n<p>    decimal_fraction = calculate_fractional_part(fractional_part)<\/p>\n<p>    return decimal_integer + decimal_fraction<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u793a\u4f8b\u4ee3\u7801<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">binary_str = &#39;101.101&#39;<\/p>\n<p>decimal_number = binary_to_decimal(binary_str)<\/p>\n<p>print(f&#39;\u4e8c\u8fdb\u5236\u5c0f\u6570 {binary_str} \u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u4e3a {decimal_number}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570<code>101.101<\/code>\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\uff0c\u7ed3\u679c\u4e3a<code>5.625<\/code>\u3002\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u51c6\u786e\u5730\u5c06\u4efb\u610f\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><h4>1\u3001\u8ba1\u7b97\u673a\u79d1\u5b66<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0c\u4e8c\u8fdb\u5236\u6570\u662f\u6700\u57fa\u672c\u7684\u6570\u503c\u8868\u793a\u5f62\u5f0f\u3002\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u5728\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u3001\u7f16\u7a0b\u8bed\u8a00\u548c\u6570\u5b57\u7535\u8def\u8bbe\u8ba1\u4e2d\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u4f20\u8f93\u548c\u901a\u4fe1<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u4f20\u8f93\u548c\u901a\u4fe1\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u8f6c\u6362\u4e3a\u5176\u4ed6\u5f62\u5f0f\u8fdb\u884c\u5904\u7406\u3002\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u548c\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u79d1\u5b66\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u5728\u79d1\u5b66\u8ba1\u7b97\u4e2d\uff0c\u5c24\u5176\u662f\u5728\u6d89\u53ca\u5230\u7cbe\u5ea6\u8981\u6c42\u8f83\u9ad8\u7684\u8ba1\u7b97\u65f6\uff0c\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u8f6c\u6362\u4e5f\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u901a\u8fc7\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\uff0c\u53ef\u4ee5\u66f4\u51c6\u786e\u5730\u8fdb\u884c\u8ba1\u7b97\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><h4>1\u3001\u7cbe\u5ea6\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u4e8c\u8fdb\u5236\u5c0f\u6570\u5230\u5341\u8fdb\u5236\u5c0f\u6570\u7684\u8f6c\u6362\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u7cbe\u5ea6\u95ee\u9898\u3002\u7531\u4e8e\u8ba1\u7b97\u673a\u4e2d\u6d6e\u70b9\u6570\u7684\u8868\u793a\u65b9\u5f0f\u6709\u9650\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cbe\u5ea6\u4e22\u5931\u3002\u56e0\u6b64\uff0c\u5728\u8fdb\u884c\u9ad8\u7cbe\u5ea6\u8ba1\u7b97\u65f6\uff0c\u9700\u8981\u683c\u5916\u5c0f\u5fc3\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8fb9\u754c\u60c5\u51b5<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u4e8c\u8fdb\u5236\u5c0f\u6570\u65f6\uff0c\u8fd8\u9700\u8981\u6ce8\u610f\u4e00\u4e9b\u8fb9\u754c\u60c5\u51b5\u3002\u4f8b\u5982\uff0c\u5f53\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u6216\u5c0f\u6570\u90e8\u5206\u4e3a\u7a7a\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u901a\u8fc7\u5224\u65ad<code>&#39;.&#39;<\/code>\u662f\u5426\u5b58\u5728\uff0c\u5e76\u5206\u522b\u5904\u7406\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\uff0c\u907f\u514d\u4e86\u8fd9\u4e9b\u8fb9\u754c\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\uff0c\u901a\u8fc7\u5206\u5272\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\uff0c\u5206\u522b\u8ba1\u7b97\u5176\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u503c\uff0c\u5e76\u5c06\u7ed3\u679c\u76f8\u52a0\uff0c\u53ef\u4ee5\u51c6\u786e\u5730\u5b8c\u6210\u8f6c\u6362\u3002\u4e0a\u8ff0\u4ee3\u7801\u793a\u4f8b\u5c55\u793a\u4e86\u5177\u4f53\u7684\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5e76\u8be6\u7ec6\u8bb2\u89e3\u4e86\u6bcf\u4e2a\u6b65\u9aa4\u7684\u8fc7\u7a0b\u548c\u6ce8\u610f\u4e8b\u9879\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8fd9\u4e00\u65b9\u6cd5\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u3001\u6570\u636e\u4f20\u8f93\u548c\u79d1\u5b66\u8ba1\u7b97\u7b49\u9886\u57df\u90fd\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>float<\/code>\u51fd\u6570\u548c\u5b57\u7b26\u4e32\u5904\u7406\u6765\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u3002\u9996\u5148\uff0c\u9700\u8981\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u5206\u5f00\uff0c\u7136\u540e\u4f7f\u7528<code>int()<\/code>\u51fd\u6570\u5c06\u6574\u6570\u90e8\u5206\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\uff0c\u5e76\u5c06\u5c0f\u6570\u90e8\u5206\u4e58\u4ee5\u76f8\u5e94\u7684\u6743\u91cd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">def binary_to_decimal(binary_str):\n    if &#39;.&#39; in binary_str:\n        integer_part, decimal_part = binary_str.split(&#39;.&#39;)\n    else:\n        integer_part, decimal_part = binary_str, &#39;0&#39;\n    \n    decimal_integer = int(integer_part, 2)\n    decimal_decimal = sum(int(bit) * (2 ** -(index + 1)) for index, bit in enumerate(decimal_part))\n    \n    return decimal_integer + decimal_decimal\n\nbinary_number = &#39;110.101&#39;\ndecimal_number = binary_to_decimal(binary_number)\nprint(decimal_number)  # \u8f93\u51fa\uff1a6.625\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u662f\u5426\u6709\u5e93\u53ef\u4ee5\u5904\u7406\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u8f6c\u6362\uff1f<\/strong><br \/>\u786e\u5b9e\u6709\u4e00\u4e9b\u5e93\u53ef\u4ee5\u7b80\u5316\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u8f6c\u6362\u8fc7\u7a0b\u3002\u6bd4\u5982\uff0c\u4f7f\u7528<code>numpy<\/code>\u5e93\u4e2d\u7684<code>frombinary<\/code>\u548c<code>tobinary<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u4e8c\u8fdb\u5236\u548c\u5341\u8fdb\u5236\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u867d\u7136\u8fd9\u4e9b\u5e93\u4e3b\u8981\u662f\u4e3a\u79d1\u5b66\u8ba1\u7b97\u8bbe\u8ba1\u7684\uff0c\u4f46\u5b83\u4eec\u7684\u5f3a\u5927\u529f\u80fd\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u3002<\/p>\n<p><strong>\u5728\u5904\u7406\u4e8c\u8fdb\u5236\u5c0f\u6570\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u5e38\u89c1\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u65f6\uff0c\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u8f93\u5165\u683c\u5f0f\u4e0d\u6b63\u786e\u3001\u6570\u5b57\u4e2d\u5305\u542b\u975e\u4e8c\u8fdb\u5236\u5b57\u7b26\uff08\u59823\u62165\uff09\u7b49\u3002\u6b64\u5916\uff0c\u5904\u7406\u5c0f\u6570\u90e8\u5206\u65f6\u53ef\u80fd\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u635f\u5931\uff0c\u56e0\u4e3a\u67d0\u4e9b\u5341\u8fdb\u5236\u5c0f\u6570\u5728\u4e8c\u8fdb\u5236\u4e2d\u65e0\u6cd5\u7cbe\u786e\u8868\u793a\u3002\u56e0\u6b64\uff0c\u786e\u4fdd\u8f93\u5165\u7684\u6b63\u786e\u6027\u548c\u7406\u89e3\u7ed3\u679c\u7684\u8868\u793a\u65b9\u5f0f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5c06\u4e8c\u8fdb\u5236\u5c0f\u6570\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u5c0f\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u89e3\u6790\u4e8c\u8fdb\u5236\u5c0f\u6570\u7684\u6574\u6570\u90e8\u5206\u548c\u5c0f\u6570\u90e8\u5206\u3001\u5c06\u6574\u6570\u90e8\u5206\u4e58\u4ee52\u7684\u5e42\u6b21\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1111237,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111232"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1111232"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111232\/revisions"}],"predecessor-version":[{"id":1111239,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1111232\/revisions\/1111239"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1111237"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1111232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1111232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1111232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}