sbgSwap.h
Go to the documentation of this file.
1 
21 #ifndef SBG_SWAP_H
22 #define SBG_SWAP_H
23 
24 //----------------------------------------------------------------------//
25 //- Header (open extern C block) -//
26 //----------------------------------------------------------------------//
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <sbgCommon.h>
32 
33 //----------------------------------------------------------------------//
34 //- Internal swap functions -//
35 //----------------------------------------------------------------------//
36 
42 SBG_INLINE uint16_t sbgSwap16(uint16_t x)
43 {
44  return ((x<<8)|(x>>8));
45 }
46 
52 SBG_INLINE uint32_t sbgSwap32(uint32_t x)
53 {
54  return ((x << 24) | ((x << 8) & (0xFF0000)) | ((x >> 8) & (0xFF00)) | (x >> 24));
55 }
56 
62 SBG_INLINE uint64_t sbgSwap64(uint64_t x)
63 {
64  uint32_t hi, lo;
65 
66  //
67  // Separate into high and low 32-bit values
68  //
69  lo = (uint32_t)(x&0xFFFFFFFF);
70  x >>= 32;
71  hi = (uint32_t)(x&0xFFFFFFFF);
72 
73  //
74  // Swap each part and rebuild our 64 bit vale
75  //
76  x = sbgSwap32(lo);
77  x <<= 32;
78  x |= sbgSwap32(hi);
79 
80  return x;
81 }
82 
88 SBG_INLINE float sbgSwapFloat(float val)
89 {
90  FloatNint tmpFloat;
91 
92  //
93  // We use a union to do the type punning
94  //
95  tmpFloat.valF = val;
96  tmpFloat.valU = sbgSwap32(tmpFloat.valU);
97 
98  //
99  // Return the swapped float
100  //
101  return tmpFloat.valF;
102 }
103 
109 SBG_INLINE double sbgSwapDouble(double val)
110 {
111  DoubleNint tmpDouble;
112 
113  //
114  // We use a union to do the type punning
115  //
116  tmpDouble.valF = val;
117  tmpDouble.valU = sbgSwap64(tmpDouble.valU);
118 
119  //
120  // Return the swapped double
121  //
122  return tmpDouble.valF;
123 }
124 
125 //----------------------------------------------------------------------//
126 //- Footer (close extern C block) -//
127 //----------------------------------------------------------------------//
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* SBG_SWAP_H */
double valF
Definition: sbgTypes.h:148
SBG_INLINE uint16_t sbgSwap16(uint16_t x)
Definition: sbgSwap.h:42
uint64_t valU
Definition: sbgTypes.h:149
SBG_INLINE float sbgSwapFloat(float val)
Definition: sbgSwap.h:88
float valF
Definition: sbgTypes.h:138
uint32_t valU
Definition: sbgTypes.h:140
#define SBG_INLINE
Definition: sbgDefines.h:186
Main header file for SBG Systems common C library.
SBG_INLINE double sbgSwapDouble(double val)
Definition: sbgSwap.h:109
SBG_INLINE uint64_t sbgSwap64(uint64_t x)
Definition: sbgSwap.h:62
SBG_INLINE uint32_t sbgSwap32(uint32_t x)
Definition: sbgSwap.h:52


sbg_driver
Author(s): SBG Systems
autogenerated on Sat Sep 3 2022 02:53:36