# C++ Program to Converter a Binary to Decimal

You are Here:

## Converter a Number from Binary to Decimal

In the following example, we will convert a Binary number (1000001) to a Decimal number (65).

Tips: It is recommended to use our online Binary to Decimal converter for better understanding.

### Example

C++ Compiler
#include <iostream> #include <cmath> using namespace std; int main() { int num = 1000001; int i = -1; int arr, j; int total = 0; while(num != 0) { i++; arr[i] = num % 10; num = num / 10; } for(j=i; j>=0; j--) total += (arr[j] * ((int) pow(2, j))); cout << "Decimal number of 1000001 (binary) is " << total; return 0; }

### Output

Decimal number of 1000001 (binary) is 65

## Converter any Given Binary Number to Decimal Number

In the following example, we will convert any given binary number to a decimal number.

### Example

C++ Compiler
#include <iostream> #include <cmath> using namespace std; int main() { int num, copyNum, arr, j; int i = -1; int total = 0; cout << "Enter a Binary Number: "; cin >> num; copyNum = num; while(copyNum != 0) { i++; arr[i] = copyNum % 10; copyNum = copyNum / 10; } for(j=i; j>=0; j--) total += (arr[j] * ((int) pow(2, j))); cout << "Decimal number of " << num << " (binary) is " << total; return 0; }

### Output

Enter a Binary Number: 25 Decimal number of 25 (binary) is 9

## Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on C++ with examples for quick and easy learning.

We are working to cover every Single Concept in C++.