Convert float to bytes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert float to bytes

702 Views
Woodman
Contributor I

Hi,

 

Create a simple project for 56F801 in CW 8.0 and find a strange problem when converting float point to bytes. Define a union

typedef union _FloatType

{

    float f;

    byte b[4];

} FloatType;

 

then define and set

FloatType f;

f.f = 2.3f;

 

In debuger window, find b[0] = 0x3333, b[1] = 0x4013, b[2] = 0; b[3] = 0

Apparently b does not point to bytes. What's the problem here?

Thanks a lot.

Labels (1)
Tags (1)
0 Kudos
1 Reply

275 Views
giacomopetrini
Contributor IV

Hi, I think it probably depends on what format the float is encoded (cfr. http://en.wikipedia.org/wiki/IEEE_754-2008 for example).

I don't know what format is used in the 56800...

 

Hope this helps

 

Bye Giacomo

0 Kudos