Seed Studio Canbus MCP2515

Hi All, i'm doing a little project that will read a can channel and so some math on it. I'm quite ok in reading a whole byte but my problem is that the channel i have to read is accross 3 bytes: The chennel is Big Endian Unsigned start bit 24 13 bit lenght, so if i'm not mistaken the data will be Most Significative BIT 0 of Byte 3 less Significative bit 4 of byte 5

therfore i will need to combine this data

3          4          5  byte
0      76543210     7654 bit
1      11111111     1111

And i'm a bit puzzeld in how to handle this in the easiest way starting from the 3 value of the buffer array that are

buff[3] buff[4] buff[5]

There are libraries for with is easier to reat the data in this way ? Thanks.

Right now i'm trying to use itoa function and the convert and scale back from char but it feels really a silly method i'm sure should be a better way to conver a byte variable into a bit array.

Well thanks for all the replyes !! :slight_smile:
Anyay i found a simpler way using bitwise operators i publish here for the newbies will face this problem like i did:

            int byte3,byte4,byte5=0;
            byte3 = buff[3];
            byte3 = byte3 << 12;
            byte4 = buff[4];
            byte4 = byte4 << 4;
            byte5 = buff[5];
            byte5 = byte5 >> 4;          
            float vel=(byte3 + byte4 + byte5);

With this code i read the whole 3 bytes from my frame and I shft those bytes into an int to have 16 bits avilable (this is actually not needed for Bit 4 and Bit 5) and i shift the data and simply sum it.
Thanks.