EV3UartGenerator
/home/shenghao/eclipse-workspace/EV3UartGenerator/simple_endian.hpp
Go to the documentation of this file.
1 
12 #ifndef SIMPLE_ENDIAN_HPP
13 #define SIMPLE_ENDIAN_HPP
14 
15 #include <stdint.h> // We can't include <cstdint> if we want to compile under Arduino
16 
17 #ifndef __BYTE_ORDER__
18 #error "__BYTE_ORDER__ is not defined by your system - are you compiling under GCC?"
19 #endif
20 
21 namespace EV3UartGenerator {
22 namespace SimpleEndian {
23 uint32_t htole32(uint32_t host_32bits) {
24 #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
25  return host_32bits;
26 #elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
27  return __builtin_bswap32(host_32bits);
28 #elif (__BYTE_ORDER__ == __ORDER_PDP_ENDIAN__)
29  return (((host_32bits & 0xffff0000) >> 0x10) | ((host_32bits & 0x0000ffff) << 0x10));
30 #elif 1
31 #error "__BYTE_ORDER__ currently defined is not supported - please submit a bug report"
32 #endif
33 }
34 }
35 }
36 
37 #endif /* SIMPLE_ENDAIN_HPP */