G
Goran
Hi!
I need to convert from a unsigned char array to a float. I don't think
i get the right results in the program below.
unsigned char array1[4] = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in
what order the data is stored so i try both ways.
unsigned char array2[4] = { 0x23, 0x44, 0xc2, 0xde};
float *pfloat1, *pfloat2;
pfloat1 = (float *)array1;
pfloat2 = (float *)array2;
printf("pfloat1 = %f, pfloat2 = %f\n", pfloat1, pfloat2);
The result here is:
pfloat1 = 0.000000, pfloat2 = -6999176012340658176.000000
I know this data is stored in single-precision floatingpoint number.
Calculating this with the formula: 1.mantissa * 2^(exp-127) gets the
following results:
-6614457784713468934.9861376 when using array1
-79.784837 when using array2.
Anyone know why i get so bad results? I'm running this program under
Linux(Red Hat) on a Intel pentium machine.
Regards,
Goran
Is there any easy way to do this?
I need to convert from a unsigned char array to a float. I don't think
i get the right results in the program below.
unsigned char array1[4] = { 0xde, 0xc2, 0x44, 0x23}; //I'm not sure in
what order the data is stored so i try both ways.
unsigned char array2[4] = { 0x23, 0x44, 0xc2, 0xde};
float *pfloat1, *pfloat2;
pfloat1 = (float *)array1;
pfloat2 = (float *)array2;
printf("pfloat1 = %f, pfloat2 = %f\n", pfloat1, pfloat2);
The result here is:
pfloat1 = 0.000000, pfloat2 = -6999176012340658176.000000
I know this data is stored in single-precision floatingpoint number.
Calculating this with the formula: 1.mantissa * 2^(exp-127) gets the
following results:
-6614457784713468934.9861376 when using array1
-79.784837 when using array2.
Anyone know why i get so bad results? I'm running this program under
Linux(Red Hat) on a Intel pentium machine.
Regards,
Goran
Is there any easy way to do this?