rework endianness handling code to avoid aliasing warnings