Augustana Faculty logo


Computer Organization and Architecture II


Testing and Byteswapping in C

These are the files from the SNDAN sound analysis program which handle byte ordering detection and conversion.

Testing and Byteswapping in C++

Here is a more sophisticated (complicated) approach in C++. It determines the byte-ordering used on the host machine in the constructor of the class Machine, storing the result for later use via the ByteOrder() function, and uses function overloading to handle the different argument sizes which might need byte-swapping.

Note that floats are byte-swapped by casting them to ints. This class is machine-dependent due to the assumption that floats and ints are both 32 bits in length, and that short ints are 16 bits long. Byte-swapping functions for other data sizes (e.g., double, long int) could easily be added.