In my ongoing poor mans light project i will transmitt a packet of bytes from a PC to my networked arduinos. The first two bytes will be the package size, which in th PC application is casted from a short int into two bytes.
Now I want to do the same thing backwards in my arduino, casting from two bytes to an int, and things like byte order must be correct.
I imagine you'll want to use BitMath, have a read up on the link, or wait a bit longer for someone to do the work for you and post here, if you prefer.
Shifting is probably better from a performance point of view rather than multiplication of integers. If speed is an issue that is.
I would think the runtime code is identical for both versions. The compiler is smart enough to know that multiplying by a number to the power of two is the same as shifting left by that number so it will do the shift in either case.
FWIW, while the multiplication approach works, I think the bitwise approach is more "standard" and it's worth familiarising oneself with it and using the approach.
Yes, bitwise would have been a better choice than logical. That's what happens when I post in a hurry. I was actually trying to differentiate between the boolean || and the bitwise | .