Mana
Memory.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include <cstdint>
10 
11 namespace mana
12 {
13  /*
14  std::endian is available from C++20
15  */
16 
17  inline bool IsBigEndian()
18  {
19  static constexpr int16_t One = 1;
20  const char* pointer = reinterpret_cast<const char*>(&One);
21  return pointer[0] == 0;
22  }
23 
24  inline int16_t SwapEndian(const int16_t value)
25  {
26  return (value << 8 & 0xFF00) | (value >> 8 & 0x00FF);
27  }
28 
29  inline uint16_t SwapEndian(const uint16_t value)
30  {
31  return (value << 8 & 0xFF00) | (value >> 8 & 0x00FF);
32  }
33 
34  inline int32_t SwapEndian(const int32_t value)
35  {
36  return (value << 24 & 0xFF000000) | (value << 8 & 0x00FF0000) | (value >> 8 & 0x0000FF00) | (value >> 24 & 0x000000FF);
37  }
38 
39  inline uint32_t SwapEndian(const uint32_t value)
40  {
41  return (value << 24 & 0xFF000000) | (value << 8 & 0x00FF0000) | (value >> 8 & 0x0000FF00) | (value >> 24 & 0x000000FF);
42  }
43 
44  inline float SwapEndian(const float value)
45  {
46  return static_cast<float>(SwapEndian(static_cast<uint32_t>(value)));
47  }
48 }
Definition: CodeBuffer.cpp:12
bool IsBigEndian()
Definition: Memory.h:17
int16_t SwapEndian(const int16_t value)
Definition: Memory.h:24