Bitshifting and bitwise or bytes to long gives wrong value

Hi,

I had to turn some bytes into a long, so I made a function to bitshift the bytes into a long.
It looked like everything was fine until I got some confusing discrepancies in my values.
Some inputs gets the wrong output. I have now tried another function that works better, but I would still like to know whats wrong with my bit shoft function.

uint32_t byteToLong_1 (uint8_t byte3, uint8_t byte2, int8_t byte1, uint8_t byte0){
  return (uint32_t)byte3<<24 | (uint32_t)byte2<<16 | (uint32_t)byte1<<8 | (uint32_t)byte0;
}

Please don't post pictures of code or Serial monitor output. Copy them and paste them here in code tags to make them more manageable and easy to read

You're missing a "u" in the byte1 argument specifier.

2 Likes

There you go. Now it works. Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.