Introduction
Control Statement
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number
- Program to Check Armstrong Number
- Program to find the sum of Natural Numbers using Recursion
Function
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle
- Program to find LCM
Array
Pointer
OOPS
No Examples found for this topic - CodeHelpPro
Program to convert Binary to Decimal Number
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);
++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.
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments