Switch to custom byte swapping function.

GCC builtins like __bswap_32 are not portable between versions.
Ok, unless there is some other compelling reason to use union, I'm merging this as is. At least people seem to agree with the actual byte swapping approach.