Convert float to bytes

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Convert float to bytes

1,311件の閲覧回数
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.

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 返信

884件の閲覧回数
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 件の賞賛
返信