OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
byteswap_portable.hpp
1/*
2 * byteswap_portable.hpp
3 *
4 * Created on: Feb 20, 2017
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_
9#define OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_
10
11#include <climits>
12
22template <typename T>
23T swap_endian_lt(T u)
24{
25 static_assert (CHAR_BIT == 8, "CHAR_BIT != 8");
26
27 union
28 {
29 T u;
30 unsigned char u8[sizeof(T)];
31 } source, dest;
32
33 source.u = u;
34
35 for (size_t k = 0; k < sizeof(T); k++)
36 {dest.u8[k] = source.u8[sizeof(T) - k - 1];}
37
38 return dest.u;
39}
40
41#endif /* OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_ */