From 9cbb10f12502aa12bea504523ebe6dc92f5feb14 Mon Sep 17 00:00:00 2001 From: Laurin Date: Fri, 2 Feb 2024 15:10:57 +0100 Subject: [PATCH] added function to convert int to hex string for small ints --- src/conversionOfNumbers/conversionOfNumbers.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 4c97fbf..6c9708c 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -49,4 +49,20 @@ unsigned int convertBinaryStrToInt(char* input){ x++; } return result; +} + +char* convertIntToHex(int input){ + int length = 1; + int rest; + char* result = (char*)malloc(sizeof(char) * length + 1); + result[length] = '\0'; + do{ + rest = input % 16; + input /= 16; + switch(rest){ + default: result[length - 1] = rest + '0'; break; + } + length--; + }while(input != 0); + return result; } \ No newline at end of file