I have a byte array of a certain size. I would like to grab it's last four bytes and put them next to each other to form a four byte hexadecimal value, in a variable. This way I can compare a four-byte CRC-32 value with my variable and check whether the CRC values are the same.
Now this is how I am doing this at the moment:
1 2 3 4 5 6 7
staticunsignedlong whole_four = 0; // This variable holds the last four bytes of the received bytes which are the CRC bytes
//Note that "MAX_INPUT" is the size of my array and "data" is just a pointer I have used as an argument to a function to point to the elements a buffer array.
whole_four = ((unsignedlong)(*(data+(MAX_INPUT-4)))<< 24) | ((unsignedlong)(*(data+(MAX_INPUT-3)))<< 16) | ((unsignedlong)(*(data+(MAX_INPUT-2)))<< 8) | ((unsignedlong)(*(data+(MAX_INPUT-1))));
So as you can see I am shifting and "or"ing the the last four elements of my array to make a four byte variable.
Now, my question is:
Is there any faster way to achieve this and reduce the amount of processing power required?
I also like to mention that I am compiling this code on an Arduino Uno.
Any help or hints is much appreciated.