Convert float to bytes

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Convert float to bytes

1,312 次查看
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 回复

885 次查看
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 项奖励
回复