المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Perform the conversion from a float decimal number to single precision (4 byte) IEEE



C++ Programming
05-20-2009, 12:11 PM
Could anyone explain for me what these code doing? Could give me an example ? thanks


typedef union ieee_754_single_precision
{
BYTE bytes[FLOAT_BYTES];
float value;
IEEE_SBITS bits;
} SIEEE_754;


void cHARTTransmitter::Float2IEEE(float fDecimalNum, BYTE *pbIEEE)
{
SIEEE_754 local;
short j = FLOAT_BYTES - 1;

local.value = fDecimalNum;

for (i = 0 ; i < FLOAT_BYTES; i++)
{
pbIEEE[i] = local.bytes[j--];
}
}

Float2IEEE((float)m_data, Data);