school/cs142/smcquay/lab04/converts.cc
2016-04-06 20:45:34 -07:00

18 lines
277 B
C++

#include <iostream>
#include <cmath>
#include "converts.h"
int str2int(string s) {
int r = 0;
int i = 0;
for(auto s_it = s.rbegin(); s_it != s.rend(); s_it++) {
if (*s_it == '1') {
r += pow(2, i);
}
i++;
}
return r;
}