Convert from unsigned char array to float!
From: Goran (red_snake1_at_hotmail.com)
Date: 08/23/03
- Next message: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Previous message: Vampire at Wicked Empire: "Re: How do I determine the mousr position in X"
- Next in thread: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Reply: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Reply: Ulrich Eckhardt: "Re: Convert from unsigned char array to float!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 23 Aug 2003 08:17:43 -0700
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
- Next message: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Previous message: Vampire at Wicked Empire: "Re: How do I determine the mousr position in X"
- Next in thread: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Reply: Christian Biesinger: "Re: Convert from unsigned char array to float!"
- Reply: Ulrich Eckhardt: "Re: Convert from unsigned char array to float!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|