I have an intermittent stream of 8bit SPI data in 32bit chunks that I need to work with that is in the form;
8bit command + 24bit signed data.
I'm on the slave side and cannot alter the command/data structure.
XC16 doesn't support uint24_t integer types, but is there a best practise for dealing with this signed conversion?
The received data gets held in a buffer and I presume the quickest method is bit shifting as follows;
command = buffer;
data = (buffer << 24) + (buffer << 16) + (buffer << 8); //Shift everything up
data >>= 8; //Shift back down (bringing 1s if negative)
but I have seen others doing an if<0 statement, so I thought it prudent to ask for the wisdom of the crowd?