数制转换问题
怎么编程将八位十六进制数(也就是三十二位二进制数)转换成浮点数?
unsigned long h = 0x20000000;
double d = (double)h;
//----------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
double d = 0.0;;
char h[9];
int i;
scanf("%8s", h);
for(i = 0; i < strlen(h); i++)
{
if(h[i] >= '0' && h[i] <= '9')
d += h[i] - '0';
else if(h[i] >= 'a' && h[i] <= 'f')
d += h[i] - 'a' + 10;
else if (h[i] >= 'A' && h[i] <= 'F')
d += h[i] - 'A' + 10;
else
puts("Error!");
if(h[i + 1])
d *= 16;
}
printf("%lf\n", d);
system("Pause");
return 0;
}
//END
[[it] 本帖最后由 cosdos 于 2008-10-1 02:02 编辑 [/it]]