Other Parts Discussed in Thread: C2000WARE
Hi,
after researching T.I. forum I understand uint8_t or char is 16 bits not 8 bits, therefore below union does not work as expected.
typedef union {
uint32_t longValue;
uint8_t charValue[4];
} unLong;
unLong unLongTemp ;
if ...
unLongTemp.charValue[0] = 135
unLongTemp.charValue[0] = 214
unLongTemp.charValue[0] = 18
unLongTemp.charValue[0] = 0
the unLongTemp.longvalue = 14024839 not expected 1234567 because each charValue is 16 bit wide
now I use below codes instead...
uint8_t i;
uint32_t longValue[4];
for (i=0; i<=charGetIndex; i++)
{
longValue[i] = charBuffer[charGetIndex];
longValue[i] = charBuffer[charGetIndex + i];
longValue[i] = charBuffer[charGetIndex + i];
longValue[i] = charBuffer[charGetIndex + i];
}
return ((longValue[0]<<24&0xFF000000) | (longValue[1]<<16&0x00FF0000) | (longValue[2]<<8&0x0000FF00) | (longValue[3]&0x000000FF))&0xFFFFFFFF;
My question is, how can I use UNION with char / uint8_t is actually 16 bits wide ?
Thanks,
Danny