BAN: You can now transform little endian data to host endian
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user