Cheng Zang

Convert float to bytes

Discussion created by Cheng Zang on Sep 26, 2011
Latest reply on Dec 15, 2011 by giacomopetrini



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.