uint32_t bytesToUnsigned(uint8_t bytes[4]
{
return bytes[0] |
bytes[1] << 8 |
bytes[2] << 16 |
bytes[3] << 24;
}
The behavior is undefined on a system with 32 bit integers because of signed arithmetic overflow (despite the fact that all the explicit types involved are unsigned, a uint8_t gets promoted to a signed integer before the left-shift operation).Right now it will work on every compiler I've tried, but it would be perfectly valid (by the ANSI specification) for a compiler to assume that the result of that function can never have the highest bit set. In friendly C, the result is well defined.