I want to convert binary count to decimal. My code snippet :
int main(){
string count;
char number;
int counter;
int score = 0;
cout << "Wpisz liczbę w systemie binarnym" << endl;
cin >> count;
count << endl;
counter = count.length();
for (int i = 0; i < counter; i++)
{
number = count[i];
int aaa = (int) number - '0' // is that correct ? I think not.
score = aaa * pow(2,i) + score;
}
count <<wynik;
return 0;
}
But my programm gives very strange scores, for example :
input : 100 (decimal 8) output : 1
input 1000 (decimal 16) output : 1
I don't know why. Can you help me ? I think, that that is the problem with char ? Am I true ?
Thanks,
Sorry for my Englosh