I'm having problems creating a 32-bit integer from a 4-byte array. In the following complete, minimal, and verifiable example, converting a byte array containing 0x00, 0x04, 0x04F, 0x45 results in 4F45 (expected result would be 44F45). I must be overlooking something fundamental here.... can anyone see where I went wrong?
void setup()
{
Serial.begin(9600);
while(!Serial);
}
void loop()
{
uint8_t bytes[4] = {0x00, 0x04, 0x4F, 0x45}; //00044F45
int32_t theInt = byteArrayToInt32(bytes);
Serial.println(theInt, HEX); //Print 4F45
delay(250);
}
uint32_t byteArrayToInt32(uint8_t* bytes)
{
uint32_t i = 0;
i |= bytes[0] << 24;
i |= bytes[1] << 16;
i |= bytes[2] << 8;
i |= bytes[3];
return i;
}
uint32_t, no difference :(