forked from Bananymous/banan-os
BAN: You can now transform little endian data to host endian
This commit is contained in:
parent
f98f3d851c
commit
0e77b4dc4e
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <BAN/Traits.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace BAN::Math
|
||||
|
@ -50,4 +51,13 @@ namespace BAN::Math
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue