You're mixing two different methods. Either use your union to swap the bytes around or use bit-shifting to move the bits around in the original object. However, bit-shifting with signed values (particularly right-shifting, I believe ... laserlight?) is not portable (different compilers could do different things).