Re: Bitfiields in C how to?
See this http://en.wikipedia.org/wiki/Bit_field but do not skip reading of the drawback section
Re: Bitfiields in C how to?
You may use bitwise filtering plus bitshift to isolate the requested information, probably like:
Code:
struct TClimate
{
int m_Temperature;
int m_Humidity;
int m_LevelOfRain;
};
TClimate ChopValue(const unsigned long ValueReadFromStation)
{
TClimate Result;
Result.m_Temperature= ValueReadFromStation& 0x0000000F;
Result.m_Humidity= ValueReadFromStation& 0x0003F800;
Result.m_Humidity>>= 11;
Result.m_LevelOfRain= ValueReadFromStation& 0x00780000;
Result.m_LevelOfRain>>= 19;
return Result;
}
Hope this helps,
Thomas