<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # C 程序:將二進制數轉換為八進制,反之亦然 > 原文: [https://www.programiz.com/c-programming/examples/octal-binary-convert](https://www.programiz.com/c-programming/examples/octal-binary-convert) #### 在此示例中,您將學習通過創建用戶定義的函數來將二進制數手動轉換為八進制,反之亦然。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 函數](/c-programming/c-functions) * [C 用戶定義的函數](/c-programming/c-user-defined-functions) * * * ## 將二進制轉換為八進制的程序 在此程序中,我們將首先將二進制數字轉換為十進制。 然后,十進制數字轉換為八進制。 ```c #include <math.h> #include <stdio.h> int convert(long long bin); int main() { long long bin; printf("Enter a binary number: "); scanf("%lld", &bin); printf("%lld in binary = %d in octal", bin, convert(bin)); return 0; } int convert(long long bin) { int oct = 0, dec = 0, i = 0; // converting binary to decimal while (bin != 0) { dec += (bin % 10) * pow(2, i); ++i; bin /= 10; } i = 1; // converting to decimal to octal while (dec != 0) { oct += (dec % 8) * i; dec /= 8; i *= 10; } return oct; } ``` **輸出** ```c Enter a binary number: 101001 101001 in binary = 51 in octal ``` * * * ## 將八進制轉換為二進制的程序 在此程序中,八進制數首先會轉換為十進制。 然后,將十進制數轉換為二進制數。 ```c #include <math.h> #include <stdio.h> long long convert(int oct); int main() { int oct; printf("Enter an octal number: "); scanf("%d", &oct); printf("%d in octal = %lld in binary", oct, convert(oct)); return 0; } long long convert(int oct) { int dec = 0, i = 0; long long bin = 0; // converting octal to decimal while (oct != 0) { dec += (oct % 10) * pow(8, i); ++i; oct /= 10; } i = 1; // converting decimal to binary while (dec != 0) { bin += (dec % 2) * i; dec /= 2; i *= 10; } return bin; } ``` **輸出** ```c Enter an octal number: 67 67 in octal = 110111 in binary ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看