Binary to decimal and reverse
I'm trying to write functions that take in a passed value and convert it. For example this function receives a char* to "25" in binary: 11001....right now it runs but it prints out 0 which is obviously wrong, it should be 25. Any pointers appreciated
Code:
main{
char* str = "11001";
int decNum = binToDec(str);
printf("%d\n", decNum);
}
int binToDec(char* bin) {
int num = *bin;
int output = 0;
for(int i=0; num > 0; i++) {
if(num % 10 == 1) {
output += pow(2, i);
}
num /= 10;
}
return output;
}