tlx
bswap_be.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/math/bswap_be.hpp
3  *
4  * bswap16_be(), bswap32_be() and bswap64_be() to swap bytes to big-endian:
5  * no-operations on big-endian systems, bswaps on little-endian systems.
6  *
7  * Part of tlx - http://panthema.net/tlx
8  *
9  * Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
10  *
11  * All rights reserved. Published under the Boost Software License, Version 1.0
12  ******************************************************************************/
13 
14 #ifndef TLX_MATH_BSWAP_BE_HEADER
15 #define TLX_MATH_BSWAP_BE_HEADER
16 
17 #include <tlx/define/endian.hpp>
18 #include <tlx/math/bswap.hpp>
19 
20 namespace tlx {
21 
22 //! \addtogroup tlx_math
23 //! \{
24 
25 /******************************************************************************/
26 // bswap16_be() - swap 16-bit integers to big-endian
27 
28 #if TLX_LITTLE_ENDIAN
29 static inline uint16_t bswap16_be(const uint16_t& v) {
30  return bswap16(v);
31 }
32 #elif TLX_BIG_ENDIAN
33 static inline uint16_t bswap16_be(const uint16_t& v) {
34  return v;
35 }
36 #endif
37 
38 /******************************************************************************/
39 // bswap32_be() - swap 32-bit integers to big-endian
40 
41 #if TLX_LITTLE_ENDIAN
42 static inline uint32_t bswap32_be(const uint32_t& v) {
43  return bswap32(v);
44 }
45 #elif TLX_BIG_ENDIAN
46 static inline uint32_t bswap32_be(const uint32_t& v) {
47  return v;
48 }
49 #endif
50 
51 /******************************************************************************/
52 // bswap64_be() - swap 64-bit integers to big-endian
53 
54 #if TLX_LITTLE_ENDIAN
55 static inline uint64_t bswap64_be(const uint64_t& v) {
56  return bswap64(v);
57 }
58 #elif TLX_BIG_ENDIAN
59 static inline uint64_t bswap64_be(const uint64_t& v) {
60  return v;
61 }
62 #endif
63 
64 /******************************************************************************/
65 
66 //! \}
67 
68 } // namespace tlx
69 
70 #endif // !TLX_MATH_BSWAP_BE_HEADER
71 
72 /******************************************************************************/
static uint32_t bswap32(const uint32_t &v)
bswap32 - generic
Definition: bswap.hpp:84
static uint64_t bswap64(const uint64_t &v)
bswap64 - generic
Definition: bswap.hpp:122
static uint16_t bswap16(const uint16_t &v)
bswap16 - generic
Definition: bswap.hpp:52