You can easily create a #define macro that'll do this for you:
#define makeLong(msb, byte2, byte3, lsb) ((msb << 24) | (byte2 << 16) | (byte3 << 8) | (lsb))
A more robust - yet slower version:
#define makeLong(msb, byte2, byte3, lsb) (((msb & 0xff) << 24) | ((byte2 & 0xff) << 16) | ((byte3 & 0xff) << 8) | (lsb & 0xff))
For example, if you're sending the value 0x11223344
MSB first over serial, you'll receive them as:
uint8 byte1 = 0x11; // value first serial read
uint8 byte2 = 0x22; // value from second serial read
uint8 byte3 = 0x33; // etc.
uint8 byte4 = 0x44;
uint32 my_long = makeLong(byte1, byte2, byte3, byte4);
If you're expecting 4 bytes to arrive, you can do something similar to this pseudo-code:
uint32 my_long = read first byte;
while(I'm still waiting for 3 more bytes)
{
value = read next byte from serial
my_long = (my_long << 8) | value
}
After you get your 4 bytes, you're done =]. This is also more scalable in the event you ever need to go to 64-bit numbers, or down to 16-bit numbers.
-robodude666