วันพุธที่ 7 เมษายน พ.ศ. 2553

Binary to Decimal

#include <iostream>

#include <string>

using namespace std;

int compute(string s){

     if(s=="")

          return 0;

     else if(s.at(s.length()-1)=='1')

          return compute(s.erase(s.length()-1,1))*2+1;

     else

          return compute(s.erese(s.length()-1.1))*2+0;

}

int main(){

     cout<<compute("1110010")<<endl;

     return 0;

}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น