1#ifndef CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL
2#error "Do not include binaryconversionprivate.h directly."
7#pragma GCC diagnostic push
8#pragma GCC diagnostic ignored "-Wsign-conversion"
16#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
17 return static_cast<std::int16_t
>((
static_cast<std::int16_t
>(value[0]) << 8 & 0xFF00) | (
static_cast<std::int16_t
>(value[1]) & 0x00FF));
19 return static_cast<std::int16_t
>((
static_cast<std::int16_t
>(value[1]) << 8 & 0xFF00) | (
static_cast<std::int16_t
>(value[0]) & 0x00FF));
28#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
29 return static_cast<std::uint16_t
>((
static_cast<std::uint16_t
>(value[0]) << 8 & 0xFF00) | (
static_cast<std::uint16_t
>(value[1]) & 0x00FF));
31 return static_cast<std::uint16_t
>((
static_cast<std::uint16_t
>(value[1]) << 8 & 0xFF00) | (
static_cast<std::uint16_t
>(value[0]) & 0x00FF));
40#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
41 return static_cast<std::int32_t
>((
static_cast<std::int32_t
>(value[0]) << 24 & 0xFF000000)
42 | (
static_cast<std::int32_t
>(value[1]) << 16 & 0x00FF0000) | (
static_cast<std::int32_t
>(value[2]) << 8 & 0x0000FF00)
43 | (
static_cast<std::int32_t
>(value[3]) & 0x000000FF));
45 return static_cast<std::int32_t
>((
static_cast<std::int32_t
>(value[3]) << 24 & 0xFF000000)
46 | (
static_cast<std::int32_t
>(value[2]) << 16 & 0x00FF0000) | (
static_cast<std::int32_t
>(value[1]) << 8 & 0x0000FF00)
47 | (
static_cast<std::int32_t
>(value[0]) & 0x000000FF));
56#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
57 return (
static_cast<std::uint32_t
>(value[0]) << 16 & 0x00FF0000) | (
static_cast<std::uint32_t
>(value[1]) << 8 & 0x0000FF00)
58 | (
static_cast<std::uint32_t
>(value[2]) & 0x000000FF);
60 return (
static_cast<std::uint32_t
>(value[2]) << 16 & 0x00FF0000) | (
static_cast<std::uint32_t
>(value[1]) << 8 & 0x0000FF00)
61 | (
static_cast<std::uint32_t
>(value[0]) & 0x000000FF);
70#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
71 return (
static_cast<std::uint32_t
>(value[0]) << 24 & 0xFF000000) | (
static_cast<std::uint32_t
>(value[1]) << 16 & 0x00FF0000)
72 | (
static_cast<std::uint32_t
>(value[2]) << 8 & 0x0000FF00) | (
static_cast<std::uint32_t
>(value[3]) & 0x000000FF);
74 return (
static_cast<std::uint32_t
>(value[3]) << 24 & 0xFF000000) | (
static_cast<std::uint32_t
>(value[2]) << 16 & 0x00FF0000)
75 | (
static_cast<std::uint32_t
>(value[1]) << 8 & 0x0000FF00) | (
static_cast<std::uint32_t
>(value[0]) & 0x000000FF);
84#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
85 return (
static_cast<std::int64_t
>(value[0]) << 56 & 0xFF00000000000000) | (
static_cast<std::int64_t
>(value[1]) << 48 & 0x00FF000000000000)
86 | (
static_cast<std::int64_t
>(value[2]) << 40 & 0x0000FF0000000000) | (
static_cast<std::int64_t
>(value[3]) << 32 & 0x000000FF00000000)
87 | (
static_cast<std::int64_t
>(value[4]) << 24 & 0x00000000FF000000) | (
static_cast<std::int64_t
>(value[5]) << 16 & 0x0000000000FF0000)
88 | (
static_cast<std::int64_t
>(value[6]) << 8 & 0x000000000000FF00) | (
static_cast<std::int64_t
>(value[7]) & 0x00000000000000FF);
90 return (
static_cast<std::int64_t
>(value[7]) << 56 & 0xFF00000000000000) | (
static_cast<std::int64_t
>(value[6]) << 48 & 0x00FF000000000000)
91 | (
static_cast<std::int64_t
>(value[5]) << 40 & 0x0000FF0000000000) | (
static_cast<std::int64_t
>(value[4]) << 32 & 0x000000FF00000000)
92 | (
static_cast<std::int64_t
>(value[3]) << 24 & 0x00000000FF000000) | (
static_cast<std::int64_t
>(value[2]) << 16 & 0x0000000000FF0000)
93 | (
static_cast<std::int64_t
>(value[1]) << 8 & 0x000000000000FF00) | (
static_cast<std::int64_t
>(value[0]) & 0x00000000000000FF);
102#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
103 return (
static_cast<std::uint64_t
>(value[0]) << 56 & 0xFF00000000000000) | (
static_cast<std::uint64_t
>(value[1]) << 48 & 0x00FF000000000000)
104 | (
static_cast<std::uint64_t
>(value[2]) << 40 & 0x0000FF0000000000) | (
static_cast<std::uint64_t
>(value[3]) << 32 & 0x000000FF00000000)
105 | (
static_cast<std::uint64_t
>(value[4]) << 24 & 0x00000000FF000000) | (
static_cast<std::uint64_t
>(value[5]) << 16 & 0x0000000000FF0000)
106 | (
static_cast<std::uint64_t
>(value[6]) << 8 & 0x000000000000FF00) | (
static_cast<std::uint64_t
>(value[7]) & 0x00000000000000FF);
108 return (
static_cast<std::uint64_t
>(value[7]) << 56 & 0xFF00000000000000) | (
static_cast<std::uint64_t
>(value[6]) << 48 & 0x00FF000000000000)
109 | (
static_cast<std::uint64_t
>(value[5]) << 40 & 0x0000FF0000000000) | (
static_cast<std::uint64_t
>(value[4]) << 32 & 0x000000FF00000000)
110 | (
static_cast<std::uint64_t
>(value[3]) << 24 & 0x00000000FF000000) | (
static_cast<std::uint64_t
>(value[2]) << 16 & 0x0000000000FF0000)
111 | (
static_cast<std::uint64_t
>(value[1]) << 8 & 0x000000000000FF00) | (
static_cast<std::uint64_t
>(value[0]) & 0x00000000000000FF);
120 const auto val = toInt32(value);
121 const auto *
const c =
reinterpret_cast<const char *
>(&val);
122 return *
reinterpret_cast<const float *
>(c);
130 const auto val = toInt64(value);
131 const auto *
const c =
reinterpret_cast<const char *
>(&val);
132 return *
reinterpret_cast<const double *
>(c);
143template <
class T, Traits::EnableIf<std::is_
integral<T>> * =
nullptr>
CPP_UTILITIES_EXPORT inline T toInt(
const char *value)
146 std::memcpy(&dst, value,
sizeof(T));
147#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
159#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
160 outputbuffer[0] =
static_cast<char>((value >> 16) & 0xFF);
161 outputbuffer[1] =
static_cast<char>((value >> 8) & 0xFF);
162 outputbuffer[2] =
static_cast<char>((value)&0xFF);
164 outputbuffer[2] =
static_cast<char>((value >> 16) & 0xFF);
165 outputbuffer[1] =
static_cast<char>((value >> 8) & 0xFF);
166 outputbuffer[0] =
static_cast<char>((value)&0xFF);
177template <
class T, Traits::EnableIf<std::is_
integral<T>> * =
nullptr>
CPP_UTILITIES_EXPORT inline void getBytes(T value,
char *outputbuffer)
179#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
182 std::memcpy(outputbuffer, &value,
sizeof(T));
190 auto *c =
reinterpret_cast<char *
>(&value);
191 auto i = *
reinterpret_cast<std::int32_t *
>(c);
192 getBytes(
i, outputbuffer);
200 auto *c =
reinterpret_cast<char *
>(&value);
201 auto i = *
reinterpret_cast<std::int64_t *
>(c);
202 getBytes(
i, outputbuffer);
206#pragma GCC diagnostic pop
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
CPP_UTILITIES_EXPORT constexpr float toFloat32(std::uint16_t fixed8value)
Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation.
CPP_UTILITIES_EXPORT constexpr std::uint16_t swapOrder(std::uint16_t value)
Swaps the byte order of the specified 16-bit unsigned integer.