//这个程序是将二进制数字转化为十进制数字
#include//for cin and cout
#include//for ifstream and ofstream
#include//for pow function
#include//for filename
using namespace std;
void printline();//print the headline
void change();//change the digits
int main()
{
printline();
change();
return 0;
}
//***********************************************************************
void change()
{
//change digits
string filename;
ifstream indata;
//open the file
indata.open(filename.c_str());
cout<<"please enter the filename";
cin>>filename;
if(!indata)
{
cout<<"can't open the file"; //check the file
}
else
{
string line;
indata>>line; //整行地读入
string::size_type n;
n=line.length();//一行有多少个数字方便乘以二的几次方
int count1=1;
int count2=1;
int count3=0;
while(count1<=n&&count2<=n)
{
int j,b;
b=substr((0+count3),1);//take the digit one by one
j=b*pow(2,n-count2);
cout<
int c=1;
while(c<=(14-n))
{
cout<<" ";
c++;
}
cout<}
count3++;
}
}
//*******************************************************************************************
void printline()
{
// print the title
cout<<"Binary Number Decimal Equivalent"<}
--------------------next---------------------
//这个程序是将二进制数字转化为十进制数字
#include //for cin and cout
#include //for ifstream and ofstream
#include
阅读(847) | 评论(0) | 转发(0) |