I am working with a sensor that outputs a 24bit value
I acquire the bytes without any problem
My first question
I tried to concatenate the three bytes into a 32bit int
uint32_t data = (byte_array[3]<<16)|(byte_array[1]<<8)|(byte_array[0]);
And I get the error
avr left shift count >= width of type
I am sure this is me being dumb but I can't see what the issue is with shifting 16 bits?
Now time for the real question
Of the 24 bits the first 16 are the integer part and the last 8 are the fractional part
The integer part is 2's complement to allow for negative values and I am so noob its actually the first time I have had to deal with this
if I concatenate the 16bit integer part like this
int16_t temp_int = ((byte_array[2]<<8)|(byte_array[1]));
I have a signed 16bit integer and this result will be all I need is this right? I was reading something that said if I want to convert a twos complement number I have to negate all bits and then add 1 but I think thats if I am working on raw bits
So my question in a nutshell is
If I use a signed int then does this convert a twos complement number for me without much thought?
Edit
I think my first problem was trying to shift an 8bit value 16bits and its obviously not long enough
uint32_t data = ((uint32_t)byte_array[3]<<16)|(byte_array[1]<<8)|(byte_array[0]);
Seems to fix it but I think I should cast the 2nd byte to a 16bit