#include <iostream> #include <iomanip> #include <cmath> using namespace std; double power(double x,int n) { double val=1.0; while(n--) val*=x; return val; } int main() { int value=0; cout<<"Enter an 8 bit binary number: "; for(int i=7;i>=0;i--) { char ch; cin>>ch; if(ch=='1') value+=static_cast<int>(power(2,i)); } cout<<"Decimal value is "<<value<<endl; return 0; }
标签:ch,val,int,double,打卡,include,4.22 From: https://www.cnblogs.com/Sunyiran/p/17342911.html