Code:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
double hex2double(const char *hex)
{
char *tmp;
if ((tmp = malloc(strlen(hex) + 3)) == NULL) {
perror("hex2double()");
exit(1);
}
if (hex[0] != '0' || hex[1] != 'x' || hex[1] != 'X') {
sprintf(tmp, "0x%s", hex);
} else {
strcpy(tmp, hex);
}
return atof(tmp);
}
int main()
{
double floatnum;
floatnum = hex2double("C203145B");
printf("Resulting double value = %f\n", floatnum);
return 0;
}
Output:
double value = 3254981723.000000