Answer to Question #39739 in C++ for Ayeza
a code on how to convert binary to decimal in c programming.
1
2014-03-13T13:30:04-0400
#include <iostream>
int binaryToDecimal(int n)
{
int output = 0;
for(int i=0; n > 0; i++)
{
if (n % 10 == 1)
output += (1 << i);
n /= 10;
}
return output;
}
int main (void)
{
std::cout << "Enter binary number: ";
int binaryNumber;
std::cin >> binaryNumber;
std::cout << "Decimal: " << binaryToDecimal(binaryNumber) << std::endl;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment