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 
43 {
44  return ((x<<8)|(x>>8));
45 }
46 
53 {
54  return ((x << 24) | ((x << 8) & (0xFF0000)) | ((x >> 8) & (0xFF00)) | (x >> 24));
55 }
56 
63 {
64  uint32 hi, lo;
65 
66  //
67  // Separate into high and low 32-bit values
68  //
69  lo = (uint32)(x&0xFFFFFFFF);
70  x >>= 32;
71  hi = (uint32)(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
double valF
Definition: sbgTypes.h:136
unsigned int uint32
Definition: sbgTypes.h:58
uint32 valU
Definition: sbgTypes.h:128
uint64 valU
Definition: sbgTypes.h:137
unsigned long long int uint64
Definition: sbgTypes.h:60
SBG_INLINE uint32 sbgSwap32(uint32 x)
Definition: sbgSwap.h:52
SBG_INLINE float sbgSwapFloat(float val)
Definition: sbgSwap.h:88
float valF
Definition: sbgTypes.h:126
SBG_INLINE uint16 sbgSwap16(uint16 x)
Definition: sbgSwap.h:42
#define SBG_INLINE
Definition: sbgDefines.h:94
Main header file for SBG Systems common C library.
SBG_INLINE uint64 sbgSwap64(uint64 x)
Definition: sbgSwap.h:62
SBG_INLINE double sbgSwapDouble(double val)
Definition: sbgSwap.h:109
unsigned short uint16
Definition: sbgTypes.h:57


sbg_driver
Author(s):
autogenerated on Sun Jan 27 2019 03:42:20