From 0e77b4dc4e26f711af916fa5f59ddf2353f95494 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 22 Feb 2023 21:47:22 +0200 Subject: [PATCH] BAN: You can now transform little endian data to host endian --- BAN/include/BAN/Math.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BAN/include/BAN/Math.h b/BAN/include/BAN/Math.h index 933bfdac4..e0778ebb1 100644 --- a/BAN/include/BAN/Math.h +++ b/BAN/include/BAN/Math.h @@ -2,6 +2,7 @@ #include +#include #include namespace BAN::Math @@ -50,4 +51,13 @@ namespace BAN::Math return (a + b - 1) / b; } + template + 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; + } + } \ No newline at end of file