I am currently working on a binary file format where the data is represented as an array of floats and the data is always supposed to be written with the little endian representation. So, currently I do something as follows:
float * swapped_array = new float[length_of_array];
for (int i = 0; i < length_of_array; ++i) {
swapped_array[i] = swap_float(input_array[i]);
}
Here the swap_float swaps the four bytes of the floating point value. Now, I was wondering if there is a way to do this in a cross platform way without iterating using this for loop and making it more computationally efficient.