diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 337c1d8..7b8667f 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -86,4 +86,24 @@ char* convertIntToHex(int input){ length--; }while(input != 0); return result; +} + +unsigned int convertHexStrToInt(char* input){ + unsigned int result = 0; + int index = strlen(input) - 1; + int exponent = 0; + while(index >= 0){ + switch(input[index]){ + case 'A': case 'a': result += 10 * pow(16, exponent); break; + case 'B': case 'b': result += 11 * pow(16, exponent); break; + case 'C': case 'c': result += 12 * pow(16, exponent); break; + case 'D': case 'd': result += 13 * pow(16, exponent); break; + case 'E': case 'e': result += 14 * pow(16, exponent); break; + case 'F': case 'f': result += 15 * pow(16, exponent); break; + default: result += (input[index] - '0') * pow(16, exponent); break; + } + index--; + exponent++; + } + return result; } \ No newline at end of file diff --git a/src/conversionOfNumbers/conversionOfNumbers.h b/src/conversionOfNumbers/conversionOfNumbers.h index d8ec7ce..3718fcc 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.h +++ b/src/conversionOfNumbers/conversionOfNumbers.h @@ -6,5 +6,6 @@ int binaryStrLen(int input); unsigned int convertBinaryStrToInt(char* input); char* convertIntToHex(int input); int hexStrLen(const int input); +unsigned int convertHexStrToInt(char* input); #endif \ No newline at end of file