Main Page
Namespaces
Namespace List
Namespace Members
All
Functions
Typedefs
Enumerations
Classes
Class List
Class Members
All
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
y
z
~
Functions
a
c
d
e
f
g
i
l
m
o
p
r
s
t
u
w
~
Variables
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
y
z
Files
File List
File Members
All
_
c
d
f
g
i
m
n
s
t
u
Functions
m
s
t
Variables
Typedefs
d
f
i
s
u
Enumerations
_
Enumerator
s
Macros
_
c
f
i
n
s
t
external
sbgECom
common
swap
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 */
sbgSwap32
SBG_INLINE uint32_t sbgSwap32(uint32_t x)
Definition:
sbgSwap.h:52
_DoubleNint
Definition:
sbgTypes.h:146
sbgCommon.h
SBG_INLINE
#define SBG_INLINE
Definition:
sbgDefines.h:186
sbgSwapFloat
SBG_INLINE float sbgSwapFloat(float val)
Definition:
sbgSwap.h:88
_DoubleNint::valU
uint64_t valU
Definition:
sbgTypes.h:149
_DoubleNint::valF
double valF
Definition:
sbgTypes.h:148
sbgSwap16
SBG_INLINE uint16_t sbgSwap16(uint16_t x)
Set of functions used to swap numbers.
Definition:
sbgSwap.h:42
_FloatNint::valF
float valF
Definition:
sbgTypes.h:138
_FloatNint::valU
uint32_t valU
Definition:
sbgTypes.h:140
sbgSwapDouble
SBG_INLINE double sbgSwapDouble(double val)
Definition:
sbgSwap.h:109
_FloatNint
Definition:
sbgTypes.h:136
sbgSwap64
SBG_INLINE uint64_t sbgSwap64(uint64_t x)
Definition:
sbgSwap.h:62
sbg_driver
Author(s): SBG Systems
autogenerated on Fri Oct 11 2024 02:13:40