Switch to custom byte swapping function.

GCC builtins like __bswap_32 are not portable between versions.
Does it have a practical impact? My compiler didn't complain about this (I think it's allowed to cast to ``unsigned char`` IIRC).