Program to convert binary number into its decimal equivalent
#include<iostream>
#include<conio.h>
using namespace std;
int pow(int base, int power);
int main()
{
int decimal_number = 0, binary_number = 0,
temp_number = 0, remainder = 0, counter = 0;
cout
<< "\n\n\t __ Program to convert Binary number into
Decimal number __";
cout
<< "\n\n\n Enter the Binary Number - ";
cin
>> binary_number;
temp_number
= binary_number;
while(binary_number != 0)
{
remainder
= binary_number % 10;
binary_number
= binary_number / 10;
decimal_number
= decimal_number + remainder * pow(2,counter);
counter++;
}
cout
<< "\n\n
Decimal Conversion of Binary Number " << temp_number;
cout << " (BASE 2) is -- " << decimal_number << " (BASE 10)";
cout << " (BASE 2) is -- " << decimal_number << " (BASE 10)";
getch();
return 0;
}
int pow(int base, int power)
{
int temp = 0, result = 1;
for (temp = 1 ; temp <= power ; temp++)
{
result
= result * base;
}
return result;
}
Check out the link for the detailed steps of how to convert binary number into decimal number - http://www.wikihow.com/Convert-from-Binary-to-Decimal
can you post binary to decimal conversion using recursion? Thanks!
ReplyDeleteohk.. we will post that one...
Deletehere is the code....
Deletehttp://facecoding.blogspot.in/2012/10/how-to-convert-binary-number-into.html