Browse Source

added function to convert int to hex string for small ints

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
9cbb10f125
  1. 16
      src/conversionOfNumbers/conversionOfNumbers.c

16
src/conversionOfNumbers/conversionOfNumbers.c

@ -50,3 +50,19 @@ unsigned int convertBinaryStrToInt(char* input){
} }
return result; 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;
}
Loading…
Cancel
Save