make endian function more general