Program to Convert Binary to Decimal

Posted poission

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Program to Convert Binary to Decimal相关的知识,希望对你有一定的参考价值。

Binary to Decimal in C++

To convert binary to decimal in C++ Programming, you have to ask to the user to enter any number in binary

to convert it into decimal, then display the equivalent decimal value on the output screen as shown here in the following program.

C++ Programming Code to Convert Binary to Decimal

Following C++ program ask to the user to enter any number in binary to convert it into decimal form, then display the result on the screen :

 

#include <iostream>
#include<string>

using namespace std;

int main()
{

long int binnum, decnum=0, i=1, rem;
cout<<"enter any binary number: ";
cin>>binnum;

 

//  循环 

while(binnum!=0)
{
rem=binnum%10;
decnum=decnum+rem*i;
i=i*2;
binnum=binnum/10;
}
cout<<"equivalent decimal value=: "<<decnum;

}

以上是关于Program to Convert Binary to Decimal的主要内容,如果未能解决你的问题,请参考以下文章

Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree

108. Convert Sorted Array to Binary Search Tree

convert decimal to binary

树Convert Sorted Array to Binary Search Tree