Binary to Decimal

    0

    8

    Giovanny Gongora

    Codiga's C++ Recipes

    Convert binary number to decimal

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    // function prototype
    int convert(long long);
    // function definition
    int convert(long long n) {
      int dec = 0, i = 0, rem;
      while (n!=0) {
        rem = n % 10;
        n /= 10;
        dec += rem * pow(2, i);
        ++i;
      }
      return dec;
    }
    
    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.