Program to convert Binary to Decimal Number

0 Suresh Chand March 28, 2021

In this example, We will learn how to convert binary number to decimal number.

To understand this example, You must have knowledge in following topics

#include <iostream>
#include <cmath>

using namespace std;

int convertBinaryToDecimal(long long);

int main()
    long long n;

    cout << "Enter a binary number: ";
    cin >> n;
    cout << n << " in binary = " << convertBinaryToDecimal(n) << " in decimal";
    return 0;

int convertBinaryToDecimal(long long n)
    int decimalNumber = 0, i = 0, remainder;
    while (n!=0)
        remainder = n%10;
        n /= 10;
        decimalNumber += remainder*pow(2,i);
    return decimalNumber;

The output of above program is

Enter a binary number: 110
110 in binary = 6 in decimal

In the above example, We have created one function convertBinaryToDecimal() which converts the binary number to the decimal number.

Notify of
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.



Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System