Octal to Binary

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Convert octal to binary number

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    long long convertOctalToBinary(int);
    long long convertOctalToBinary(int octalNumber) {
      int decimalNumber = 0, i = 0;
      long long binaryNumber = 0;
      while(octalNumber != 0) {
        decimalNumber += (octalNumber%10) * pow(8,i);
        ++i;
        octalNumber/=10;
      }
      i = 1;
      while (decimalNumber != 0){
        binaryNumber += (decimalNumber % 2) * i;
        decimalNumber /= 2;
        i *= 10;
      }
      return binaryNumber;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.