I'm having the following problem:
I have an uint8_t h_MSB and uint16_t h_LSB and iwant to combine them into a uint32_t
So here is my code:
void parseHeader(MyPackage Header,uint32_t* timeStamp ){
(*timeStamp) = (Header->h_MSB <<16)| Header->h_LSB;
}
But it does not seem to work;
I tried it with h_MSB = 10 and h_LSB= 10
I get 10 for the timestamp.
The problem seems to be that if I shift beyon 7 bit all information from
h_MSB ist lost, but how can it be since timestamp is a uint32_t ?
The problem is that
h_MSBisuint8_tand the shift operation is performed within theuint8_ttype (or possibly withinuint16_t, but it doesn't matter), so you get0. Cast it touint32_tbefore shifting: