32#ifndef eman__byteorder_h__
33#define eman__byteorder_h__ 1
78 if (!small_num_addr) {
82 bool data_big_endian =
false;
83 size_t typesize =
sizeof(T);
84 char *d = (
char *) small_num_addr;
87 data_big_endian =
false;
88 for (
size_t i = typesize / 2; i < typesize; i++)
91 data_big_endian =
true;
97 data_big_endian =
true;
98 for (
size_t j = 0; j < typesize / 2; j++) {
100 data_big_endian =
false;
106 return data_big_endian;
115 swap_bytes < T > (data, n);
125 swap_bytes < T > (data, n);
131 template <
class T >
static void swap_bytes(T * data,
size_t n = 1)
134 size_t p =
sizeof(T);
135 char *d = (
char *) data;
138 for (
size_t i = 0; i < n; i++, d += p) {
139 for (
size_t j = 0; j < p / 2; j++) {
ByteOrder defines functions to work on big/little endian byte orders.
static bool is_host_big_endian()
static bool is_host_endian_checked
static bool host_big_endian
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
static void become_little_endian(T *data, size_t n=1)
convert data from host byte order to little endian order.
static bool is_data_big_endian(const T *small_num_addr)
given a pointer to a reasonable small integer number, return whether the number is big endian or not.
static bool is_float_big_endian(float small_number)
given a small floating number, return whether the number is in big endian or not.
static void become_big_endian(T *data, size_t n=1)
convert data from host byte order to big endian order.