How can I convert an integer to a hexadecimal string in C?
Example: The integer 50 would be converted to the hexadecimal string "32" or "0x32".
How can I convert an integer to a hexadecimal string in C?
Example: The integer 50 would be converted to the hexadecimal string "32" or "0x32".
This answer is for those, who need to start from string in decimal representation (not from int).
int atoi( const char * str ); functionsprintf function with %x as a format parameter and you integer as a value parameterHere is a working example: https://ideone.com/qIoHNW
#include <stdio.h>
int main(void) {
int n;
char hex_val[50];
n = atoi("100663296");
sprintf(hex_val, "%x", n);
printf("%s", hex_val);
return 0;
}