user53822: 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;
}


user40318: The problem is that you are trying to shift uint8_t more than 8 bits and then OR it with int32_t.
You have to cast the uint8_t to int32_t before doing the shift.
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(1000);
}

int32_t byteArrayToInt32(uint8_t* bytes)
{
    int32_t i = 0;
    i |= (int32_t) bytes[0] << 24;
    i |= (int32_t) bytes[1] << 16;
    i |= (int32_t) bytes[2] <<  8;
    i |= (int32_t) bytes[3];
    return i;
}


53822: <p>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 <code>0x00, 0x04, 0x04F, 0x45</code> results in <code>4F45</code> (expected result would be <code>44F45</code>). I must be overlooking something fundamental here.... can anyone see where I went wrong?</p>

<pre><code>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] &lt;&lt; 24;
    i |= bytes[1] &lt;&lt; 16;
    i |= bytes[2] &lt;&lt; 8;
    i |= bytes[3];
    return i;
}
</code></pre>
 40318: <p>The problem is that you are trying to shift <code>uint8_t</code> more than 8 bits and then <code>OR</code> it with <code>int32_t</code>.</p>

<p>You have to <code>cast</code> the <code>uint8_t</code> to <code>int32_t</code> before doing the shift.</p>

<pre><code>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(1000);
}

int32_t byteArrayToInt32(uint8_t* bytes)
{
    int32_t i = 0;
    i |= (int32_t) bytes[0] &lt;&lt; 24;
    i |= (int32_t) bytes[1] &lt;&lt; 16;
    i |= (int32_t) bytes[2] &lt;&lt;  8;
    i |= (int32_t) bytes[3];
    return i;
}
</code></pre>
