'commit'
This commit is contained in:
34
C++课程/第二课字节与进制转换/2to10.cpp
Normal file
34
C++课程/第二课字节与进制转换/2to10.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<conio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> x<><78>n<EFBFBD>η<EFBFBD>
|
||||
double power (int x, int n)
|
||||
{
|
||||
int result=1;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
result=result*x;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int all=0;
|
||||
string p = "1011";
|
||||
for( int i=0;i<p.length();i++)
|
||||
{
|
||||
if(p[p.length()-i-1]=='1')
|
||||
{
|
||||
all=all+power(2,i);
|
||||
}
|
||||
}
|
||||
cout<<all<<endl;
|
||||
|
||||
getch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user