BAN: You can now transform little endian data to host endian

This commit is contained in:
Bananymous 2023-02-22 21:47:22 +02:00
parent f98f3d851c
commit 0e77b4dc4e
1 changed files with 10 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <BAN/Traits.h> #include <BAN/Traits.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
namespace BAN::Math namespace BAN::Math
@ -50,4 +51,13 @@ namespace BAN::Math
return (a + b - 1) / b; return (a + b - 1) / b;
} }
template<integral T>
inline constexpr T little_endian_to_host(const uint8_t* bytes)
{
T result = 0;
for (size_t i = 0; i < sizeof(T); i++)
result |= (T)bytes[i] << (i * 8);
return result;
}
} }