码迷,mamicode.com
首页 > 其他好文 > 详细

Program to Convert Binary to Decimal

时间:2019-05-28 17:09:57      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:pac   long   space   tput   ios   you   into   wing   user   

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

标签:pac   long   space   tput   ios   you   into   wing   user   

原文地址:https://www.cnblogs.com/poission/p/10935667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!