How to implement a program to determine the endianness of a machine and explanation of the code?