subroutine for endianness conversion