-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblBytesManipulation.hpp
More file actions
57 lines (38 loc) · 1.55 KB
/
blBytesManipulation.hpp
File metadata and controls
57 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef BL_BYTESMANIPULATION_HPP
#define BL_BYTESMANIPULATION_HPP
//-------------------------------------------------------------------
// NOTE: These functions are defined within the
// blAlgorithmsLIB namespace
//-------------------------------------------------------------------
namespace blAlgorithmsLIB
{
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Generic functions swapping bytes from
// little endian to big endian and viceversa
//-------------------------------------------------------------------
template<typename blDataType>
inline blDataType swapEndianess(const blDataType& value)
{
blDataType swappedValue;
for(int i = 0; i < sizeof(blDataType); ++i)
{
reinterpret_cast<unsigned char*>(&swappedValue)[i] = reinterpret_cast<const unsigned char*>(&value)[sizeof(blDataType) - 1 - i];
}
return swappedValue;
}
template<typename blDataType>
inline void swapEndianess(const blDataType& sourceValue,
blDataType& destinationValue)
{
for(int i = 0; i < sizeof(blDataType); ++i)
{
reinterpret_cast<unsigned char*>(&destinationValue)[i] = reinterpret_cast<const unsigned char*>(&sourceValue)[sizeof(blDataType) - 1 - i];
}
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// End of namespace
}
//-------------------------------------------------------------------
#endif // BL_BYTESMANIPULATION_HPP