diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index fadc59a..337c1d8 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "conversionOfNumbers.h" @@ -42,12 +43,12 @@ char* convertIntToBinaryStr(int input){ unsigned int convertBinaryStrToInt(char* input){ unsigned int result = 0; - int x = 0; - while(input[x] != '\0'){ - if(input[x] == '1'){ - result += 1 * pow(2, x); - } - x++; + int index = strlen(input) - 1; + int exponent = 0; + while(index >= 0){ + if(input[index] == '1') result += 1 * pow(2, exponent); + index--; + exponent++; } return result; }