Qualcomm Interview Question

Function to convert a binary string to a integer

Interview Answers

Anonymous

Apr 5, 2011

#include #include using namespace std; int binarypower(int power){ int dec=1; if(power==0) return 1; else for(int c=1;c=0;i--){ if(a[i]=='0'){ k++; continue; } else if(a[i]=='1'){ sum+=binarypower(k); k++; } } cout<

Anonymous

Jun 5, 2013

//binary_num is an array of chars with '0' and '1' s ctr=sizeof(binary_num); for(int i=0 ; i < ctr ; i++ ) { switch(binary_num[i]) { case '0' : //nothing break; case '1': dec_num+=1<